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);
            }
        });
    } 

try...

$.ajax({
   type: "POST",
   url: "delete_ajax.php",
   data: dataString,
   cache: false,
success: function(html){
   window.location.replace("http://www.domain.com");
}

still the same, dude...

$('.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>

the whole script if it helps

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).

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?

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

ok thanks i;ll try to find it

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");
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.