[英]Difference between async post request and form post
I made a website in django 1.7. 我在Django 1.7中建立了一个网站。
First I tried sending asynchronous post request with the help of jquery - 首先,我尝试借助jquery发送异步发布请求-
$.post('http://mywebsite.com/info',{params: params})
.done(function(data)
{
if(data.data != 'OK')
alert('Something Went Wrong');
else
{
alert('OK');
}
})
It worked fine on desktop but did not worked at all in my mobile. 它在台式机上运行良好,但在我的手机上根本无法运行。
I thought may be it was due to speed of net connection. 我以为可能是由于网络连接速度所致。
Then I tried posting HTML form and reloading the page- 然后,我尝试发布HTML表单并重新加载页面-
<form id="list-form" method="post" class="hide">
{% csrf_token %}
<my params >
</form>
And it worked fine on both desktop and mobile. 而且它在台式机和移动设备上都能正常工作。
So what is the difference in doing the above two methods. 那么执行以上两种方法有什么区别。 I guessed that asynchronous post request must be faster than posting a form and also reloading the page but it failed in mobiles. 我猜想异步发布请求必须比发布表单和重新加载页面更快,但是在移动设备中失败了。
Any suggestions are welcome. 欢迎任何建议。
And if there is anything else that I can do to avoid reloading the page. 如果还有其他方法可以避免重新加载页面。
Thanks in advance. 提前致谢。
The only difference that "async post request" is AJAX-request, so it has additional header "X-Requested-With: XMLHttpRequest". “异步发布请求”的唯一区别是AJAX请求,因此它具有附加的标头“ X-Requested-With:XMLHttpRequest”。
But in normal situation it should not lead to troubles you experienced. 但是在正常情况下,它不会导致您遇到的麻烦。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.