admin管理员组文章数量:1435859
I can send a POST request and render the response as a full page via submitting a form. How can I do that via a ajax request? That is:
$.ajax('test', {
'method': 'POST',
'success': function(res) {
// open a new page, render res as a full page
// I can't simply do window.location = "foobar" as it's a POST
}
});
Or, if this is strange, what is the conventional way of doing it?
I can send a POST request and render the response as a full page via submitting a form. How can I do that via a ajax request? That is:
$.ajax('test.', {
'method': 'POST',
'success': function(res) {
// open a new page, render res as a full page
// I can't simply do window.location = "foobar" as it's a POST
}
});
Or, if this is strange, what is the conventional way of doing it?
Share Improve this question asked Mar 7, 2015 at 10:44 BoyangBoyang 2,5765 gold badges34 silver badges50 bronze badges 3- 2 Why did you choose ajax for this task? – Piotr Łużecki Commented Mar 7, 2015 at 10:47
-
Submit the form using
method="POST"
instead of using script if the result page is html – mplungjan Commented Mar 7, 2015 at 10:47 - The whole idea of using Ajax is to not render a plete new page. – GolezTrol Commented Mar 7, 2015 at 10:59
2 Answers
Reset to default 3If you just need to open result of your form processing in new page you don't need ajaxa and you can just use target property of form like
<form action="http://test./" method="post" target="_blank">
Your inputs, etc.
</form>
Well i would go for form if you don't care about response at this point. But if you do, you can check response and do something like this:
$.ajax('test.', {
'method': 'POST',
'success': function(res) {
if ( res.code == 200 )
document.location = 'page1.htm';
else
alert('error!');
}
});
本文标签: javascriptHow to do post request and render response as a new pageStack Overflow
版权声明:本文标题:javascript - How to do post request and render response as a new page? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745656644a2668745.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论