Skip to main content

How to Send a JSON Request

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".
  • FACT: JavaScript was developed at Netscape by Brendan Eich, and was originally called Mocha.
  • 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.
  • Step 5: Post a JSON request. sends a request, gets a response, parses or analyzes the response, and returns a serial number. Specify these parameters in the request: the URL to post to; the JavaScript object or array to send; and the done function that is called when the request is complete and the serial number is returned.
  • TIP: Add a timeout value in milliseconds for the response.
  • Step 6: Write a as follows. The URL is the URL you are trying to post to.
  • Step 7: Know the three methods a JSON request provides. A JSON request is a global object that uses a safe subset of the programming language JavaScript. The three methods a JSON request uses are post, get, and cancel.

Popular Categories