# Use In Ajax

The following JavaScript code shows how a client can use XMLHttpRequest to request an object in JSON format from the server:

    var my_JSON_object = {};

    var http_request = new
      XMLHttpRequest();
    http_request.open(
      "GET", url, true);

    http_request.onreadystatechange
      = function ()
    {
      var done = 4, ok = 200;
      if (http_request.readyState
          == done &&
        http_request.status
          == ok) {

        my_JSON_object =
          JSON.parse(
          http_request.responseText);
      }
    };
    http_request.send(null);

Remember: XMLHttpRequest is limited by the same origin policy (the URL replying to the request must reside within the same DNS domain as the server that hosts the page containing the request).