开发者

ajax redirect issue

i want to redirect form after ( success ) to another page. i use this code

开发者_如何学C
$(document).ready(function(){
$("#ajax-form").submit(function(){
    $.post(
        "ajaxContact/ajax-register.php",
        $("#ajax-form").serialize(),
        function(data){
            if (data.success)
                $("span#ajax-message").css({'color':'green'});
               window.location("index.html");
            else
                $("span#ajax-message").css({'color':'red'});
            $("span#ajax-message").html(data.message);
        },
        "json"
    );
    return false;
});

});

how to redirect.

Regards


If you want to just redirect the page there, this should work:

if(data.success)
    window.location = "url";

Updated:

$(document).ready(function()
{
     $("#ajax-form").submit(function()
     {
          $.post("ajaxContact/ajax-register.php", $("#ajax-form").serialize(), 
          function(data)
          {
                if (data.success)
                {
                    //If successful...
                    window.location = 'http://www.google.com';
                }
                else
                {
                    //If unsuccessful...
                    alert("Post was unsuccessful."); 
                }                    
          },"json");

    return false;
    });
});

That should work for you as long as your post is returning successfully. Here's a demo using a confirm to imitate your Post:

Demo here


window.location = "http://www.google.com";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜