[英]How to send ajax request on one page and receive response on another page
I'm trying to send Ajax request using jquery and HTML5. 我正在尝试使用jquery和HTML5发送Ajax请求。 I have several pages in my application.
我的申请中有几页。 Is it possible to make Ajax request on a page(eg sync.html) and receive response on a different page(eg home.html).
是否可以在页面(例如sync.html)上发出Ajax请求并在其他页面(例如home.html)上接收响应。 I know there are other approaches to this like web-sockets and long pooling but if it's possible to achieve this using Ajax then that will make my work easier preventing me from changing any server configurations.
我知道还有其他解决方法,例如网络套接字和长池化,但是如果可以使用Ajax做到这一点,那么这将使我的工作更加轻松,从而防止我更改任何服务器配置。 I'm using ASP.NET,C# on the server side.
我在服务器端使用ASP.NET,C#。 The reason why I'm doing this is to prevent users from waiting for the response before they resume doing any other activity because this might take long depending on the size of data sent to server and the internet speed.
我这样做的原因是为了防止用户在继续执行任何其他活动之前等待响应,因为这可能需要很长时间,具体取决于发送到服务器的数据大小和Internet速度。
$.ajax({
dataType: 'jsonp',
jsonp: 'jsonp_callback',
url: server_url,
data: {
number_chunksdone : num_chunksdone,
sync_data: round_1_sync_data,
organisation_id: organisation_id,
sync_id: sync_id,
instrument_id: instrument_id,
user_id: user_id,
sync_data_2: round_2_sync_data
},
success: function (j) {
},
error: function (jqXHR, textStatus, errorThrown) {
}
});
Any idea? 任何想法?
You can try writing Location.replace()
or Location.assign()
method inside success function. 您可以尝试在成功函数中编写
Location.replace()
或Location.assign()
方法。 For eg, document.location.replace('home.html');
例如,
document.location.replace('home.html');
The Location.replace()
method replaces the current resource with the one at the given URL. Location.replace()
方法用给定URL处的资源替换当前资源。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.