0

i have done this ajax script so i can delete a page. it works fine the page is deleted from the database but after clicking delete the browser remains on the same page. after i refresh i get a 404. how can i redirect after success to first page?

this is the script

jConfirm('Sure you want to delete this?', '', 
    function(r) 
    {
        if(r==true)
        {
            $.ajax({
            type: "POST",
            url: "delete_ajax.php",
            data: dataString,
            cache: false,
            success: function(html){
            alert(dwjlddhjds);
            }
        });
    } 
3
Contributors
9
Replies
32
Views
3 Years
Discussion Span
Last Post by OsaMasw
0
$('.delete').die('click').live("click",function() 
{
    var ID = $(this).attr("id");
    var dataString = 'groove_id='+ ID;

    jConfirm('Sure you want to delete this?', '', 
    function(r) 
    {
        if(r==true)
        {
            $.ajax
            ({
                type: "POST",
                url: "delete_ajax.php",
                data: dataString,
                cache: false,
                success: function(html)
                {
                    window.location.replace("http://localhost/");
                }
            });
        } 
    });
    return false;
});




<a class="delete" href="#" id="<?php echo $groove_id;?>" rel="<?php echo $groove_id;?>" title="Delete">Delete</a>
0

Ok, so if you tried window.location.replace("http://localhost/"); on its own, you'll find that it does initiate a redirect. Are you sure that in your code, you are reaching the "success" point in the ajax method? You can easily test your code by logging to the console (console.log("x")), or by using the alert method (i prefer logging to the console log).

0

sorry for the delay JorxeM. No you are right it doesnt reach the success. Neither the alert or (console.log("x")) work. But it deletes from database. What should i do?

0

Focus on your server side code and break it up into chunks so you can figure out where the failure is. Is there code after the DB part that succeeds?

Can you run the server side page directly with a browser to get error information?

Sorry, I'm an asp.net web dev..very light on php

0

in your server side script try to return an output in case of success ex. php
echo "done";
in jquery

success: function(response) {
                if (response == "done"){
                window.location.href = "http://yoursite.com/yourpage";
                    }else{
                alert ("some error happened");
    }
}

Edited by OsaMasw

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.