Hi all, I am having a problem with this js function. If I make it redirect then the rest of the script does nothing. However if I remove the line: window.location.href = "index.php?page=news&cmd=comments&newsid=" + pageid + "&del=1" then all is fine except then there is no redirecting... so what do I need to be doing here?

function delete_comment(pageid, commentid, type){

        var answer = confirm("Are you sure you want to delete this comment?");

        if(answer == true){

                initialize();

                var infoStr = "cmd=" + encodeURIComponent(escape('delete_comment'));
                infoStr += "&commentid=" + encodeURIComponent(escape(commentid));
                infoStr += "&type=" + encodeURIComponent(escape(type));
                var url = "ajaxrequest.php";

                request.open('POST',url, true);
                request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                request.send(infoStr);
                
                window.location.href = "index.php?page=news&cmd=comments&newsid=" + pageid + "&del=1";
                
                request.onCompletion = function(){

                       window.location.href = "index.php";

                }

        }

}

Thanks for your time.

i am also facing the same problem. after a long search n research i noticed that ajax will not redirect from a page but it can only update the content in a page. just put a statement like before window.location.href
alert("succes");

this way solved my problem in IE 6/7/8 and firefox browsers.
If you have any other solution plz share.

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.