JSON requests are used to exchange data -- but not functions or expressions -- between a web page and a server. This protects users from potentially harmful attacks by a web page.
- Step 1: Be aware of the reasons a JSON Request could be rejected. The URL may not be properly formatted, the send value can't be serialized, the done value is not a function, or the timeout value is not positive.
- Step 2: Cancel a JSON request using JSONRequest.cancel. Write the following: JSONRequest.cancel(requestNumber); using the valid request number you used to send the request. If the JSON request is canceled, you will get an exception message that says "canceled".
- Step 3: Queue the request. Both JSONRequest get and post verify the parameters, queue the request, and return a request number when done. The browser you use must be able to keep open two requests per host per page.
- Step 4: Get a JSONrequest using JSONrequest.get. Type the following. The URL is the URL you are trying to get a reply from.
- TIP: Add a timeout value in milliseconds for the response.
- Step 6: Write a JSONrequest.post as follows. The URL is the URL you are trying to post to.