0

I have two pages A.html and B.html. For A I will make Ajax request to a server using jQuery, long task would run and data would be received in the success callback function. But I would navigate to B after the Ajax request. I want to have response to display on page B. Please help me to design a solution for it. Thank you

Gautam Mokal
  • 171
  • 1
  • 4
  • That would require the server side code to be in on the act - as you've provided no information about the server side (server, language, platform) it's not possible to even know if what you want to do can be handled by the server – Jaromanda X Dec 16 '16 at 00:02

1 Answers1

0

You could just redirect the user to B.html and send the data as a url parameter.

On A.html:

function callback(data) {
    //run code to check to make sure the data is valid, and stuff like that


   //then redirect the user to B.html with the data as a URL parameter
   window.location.href = "/B.html?data=" + encodeCallbackData(data);
}

You would need to implement the encodeCallbackData() function. If the response type is JSON, it might look like this:

function encodeCallbackData(data) {
    return encodeURIComponent(JSON.stringify(data));
}

then, on B.html

if (getParameterByName("data") !== null) {
    var json = JSON.parse(decodeURIComponent(getParameterByName("data")));
    // json is a variable containing the object resulting from the AJAX request.
    //do something with json
    //show the success message.
} else {
    //the user was not redirected from `A.html`.
}

getParameterByName can be found on this stack overflow answer.

Community
  • 1
  • 1
jeffkmeng
  • 851
  • 1
  • 8
  • 30