简体   繁体   English

如何在一页上发送Ajax请求并在另一页上接收响应

[英]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.

相关问题 来自一个页面的Ajax请求和另一个页面中的响应 - Ajax request from one page and response in another page 如何将从Ajax请求收到的响应重定向到另一个HTML页面 - How to redirect response received from an Ajax request to another html page 当两个页面都打开时,使用AJAX从一个页面发送JSON数据并从另一页面动态接收 - Send JSON data from one page and receive dynamically from another page using AJAX when both page are open 如何发送ajax请求并重定向到另一个页面 - How can I send an ajax request and redirect to another page 如何在 Ajax 请求中发送当前页码 - How to send current page number in Ajax request 如何将ajax响应值传递给另一个页面? - how to pass ajax response value to another page? 如何通过ajax提取api响应将从laravel控制器接收的数据发送到另一页 - how to send data received from laravel controller to another page through ajax fetch api response 使用Ajax发送数组并在ASP Classic页面中接收它 - Send an Array with Ajax and receive it in ASP Classic page Ajax - 来自另一页的响应 - Ajax - Response from another page 我想将数据发送到 php 文件进行处理并使用 ajax 接收响应而不刷新页面 - I want to send data to a php file for processing and receive a response using ajax without page refresh
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM