Forum Moderators: open

Message Too Old, No Replies

Submitting two url requests - POST then GET

         

awsoo

7:35 pm on Oct 24, 2018 (gmt 0)

5+ Year Member



Hi,

I'm developing a Ajax page that requests two urls. The first is a POST request and the second is a GET request.
I'm using time as a method between requests because the GET request is only valid after the POST is made.

My questions are:
Is there any better way to start the GET request after POST without being time?

How to obtain all the info from the POST request (cookie, headers, etc) and made available with the GET request?
This is for the server to reconize the POST and GET coming from the same machine, user and browser.

Thanks

NickMNS

7:45 pm on Oct 24, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Is there any better way to start the GET request after POST without being time?

Yes use a promise. You make the first request, if and only if it returns a valid response do you then make the second request.
[developer.mozilla.org...]

How to obtain all the info from the POST request (cookie, headers, etc) and made available with the GET request?

How? will depend on what type of a response that is returned by the post request. To make the response data available store what you need in an object or var.

BTW using a timer between requests is not ideal as the time required between requests can vary greatly depending on factors outside of your control, most notably a slow network. Set the timer too short you wont get response back in time, set it too long and the session might time-out, this means that the data returned by the post and used for get will be obsolete, thus requiring you to start over.