AjaxSubmit with window.location on response

Question!

I have a problem with ajaxSubmit... The problem is that, when I submit a form and get a response from PHP that have a script with window.location, the page doesn't change at all...

My PHP script just returns a script with window.location when the form is submitted correctly, otherwise, it returns a JSON that is parsed on the success function.

Using the tools of Chrome, I see that it loads the window.location URL on the Network Tab but, it doesn't show it to the user...

Here's the code I have:

$("form").submit(function(e) {
    e.preventDefault();
    $("form").ajaxSubmit({
        success: function(resp){
            try{
                resp=JSON.parse(resp);
                alert(resp["error"]);
            } catch(e){
                $("<div></div>").html(resp);
            }

        }
    });
    return false;
});

How do I need to do to make it work? Is there any property of options parameter of AjaxSubmit that could solve that?



Answers
Just provide URL without JS code in your server answer and then execute :

$("form").submit(function(e) {
    e.preventDefault();
    $("form").ajaxSubmit({
        success: function(resp){
            try{
                resp=JSON.parse(resp);
                window.location.href = resp;
            } catch(e){
                $("<div></div>").html(resp);
            }

        }
    });
    return false;
});
By : sdespont


This video can help you solving your question :)
By: admin