AjaxSubmit with a window.

I have a problem with ajaxSubmit ... The problem is that when I submit the form and get a response from PHP that has 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 JSON, which is parsed for a success function.

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

Here is 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 make it work? Is there any property of the options parameter AjaxSubmit that could solve this?

+4
source share
1 answer

Just provide the URL without the JS code in the server response and do:

 $("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; }); 
+1
source

Source: https://habr.com/ru/post/1442271/


All Articles