开发者

ajax redirect issue

开发者 https://www.devze.com 2023-02-13 04:46 出处:网络
i want to redirect form after ( success ) to another page. i use this code 开发者_如何学C$(document).ready(function(){

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

精彩评论

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