jquery - Javascript redirect after POST, Submit analog -
i dont have form on page, on button click need go seconpage.asp , post requeried post data
$.ajax({ type: "post", url: url, data: data, success: success, datatype: datatype });
will if load post url after post full submit analog, not redirect page if there form on page , button submit. if redirect on success, page load defaults whithout post data
so if send post
$.ajax({ type: "seconpage.asp", url: url, data: "hello works", success: function(){ location.href="seconpage.asp"; }, datatype: datatype });
then loads seconpage.asp
need "hello works" nothing seconpage.asp
contains only
<%=request.form%>
so not submit analog, because submit load page post data, instead of redirect load new page without post data
$.ajax({ type: "post", url: url, data: data, success: function(){ location.href="target-page.asp"; }, datatype: datatype });
remember if using type-submit button, have prevent default behaviour or return false:
$('#form').on('submit', function(e){ e.preventdefault(); // can use $.ajax({ /*...*/ }); return false; // or });
edit:
after see post update see problem. pass data need pass through variable:
$.ajax({ type: "post", url: url, data: { mydata: "hello works" }, success: function(){ location.href="target-page.asp"; }, datatype: datatype });
then, in controller or server-side method, manage data received.
check jquery ajax docs more information ajax options , how proceed.
Comments
Post a Comment