I have a jQuery function that processes a form and returns a message, but I need it If the response is a URL, then it detects the process and redirects to that URL.
This is my code:
$ Ajax ({type: "POST", url: url, data: $ ('#' + id_form). Serialize (), success: function (data) {if (data == 1) {window.location.reload () ;} Other {respuesta.innerHTML = data;}}});
I would recommend changing server side's return value:
< Pre>if (some) Jason comes back {IsUrl = true, data = "theUrl"}; Return Jason {IsUrl = false, data = "some messages"};
Then in your AJAX call:
Success: function (data) {if (data.IsUrl == true) {window.location = data information ; } Other {respuesta.innerHTML = data.data; }}
No comments:
Post a Comment