0

I'm trying to send Ajax request using jquery and HTML5. I have several pages in my application. Is it possible to make Ajax request on a page(e.g sync.html) and receive response on a different page(e.g 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. I'm using ASP.NET,C# on the server side. 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.

 $.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?

4
  • You need to mention the page to where request need to be send
    – Harshit
    Aug 10, 2015 at 7:17
  • from my edit you can see am sending the request to server_url
    – joseluke
    Aug 10, 2015 at 7:38
  • So what is the problem? It will call & send the request to the specified URL.
    – Harshit
    Aug 10, 2015 at 7:40
  • The problem is when i move to a different page before receiving response from server the Ajax call is aborted
    – joseluke
    Aug 10, 2015 at 7:45

1 Answer 1

0

You can try writing Location.replace() or Location.assign() method inside success function. For e.g., document.location.replace('home.html'); The Location.replace() method replaces the current resource with the one at the given URL.

3
  • Could you expand your answer and show the how it would work? Your current answer is a little hard to understand. Aug 10, 2015 at 10:33
  • @Rohan Asodekar thanks for your response. But I dont think your answer will help me because you are using Location.replace() or Location.assign() inside success function which means Ajax processing is done and server has responded. In my case one can move away from home.html before the server side processing is done
    – joseluke
    Aug 10, 2015 at 14:10
  • Another approach to this problem might be to merge the two pages into one but that will involve a lot of re-engineering which might take longer than expected and break some of the existing functionality.
    – joseluke
    Aug 13, 2015 at 7:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.