title: Google CSE (Chrome Extension) - Parsing JSON Data with JS
body: <p>I am attempting to query my Google custom search engine in my Chrome extension, and parse the returned JSON.</p>
  
  <p>My goal is to utilize the current tab URL in my request to the CSE, so I tried to adapt the sample code from the <a href="https://developer.chrome.com/extensions/examples/tutorials/getstarted.zip" rel="nofollow">Image Search example</a> that Google provides, since it is somewhat similar.</p>
  
  <p>The code uses an XMLHTTPRequest to communicate with the custom search server:</p>
  
  <pre><code> var x = new XMLHttpRequest();
   x.open('GET', searchUrl);
  
   // The Google image search API responds with JSON, so let Chrome parse it.
   x.responseType = 'json';
   x.onload = function() {
  
   // Parse and process the response from Google Image Search.
   var response = x.response;
   alert(response);
   if (!response || !response.responseData || !response.responseData.results ||
      response.responseData.results.length === 0) {
    errorCallback('No response from Google Image search!');
    return;
  }
  </code></pre>
  
  <p>Whenever I try to view the response var, it is undefined. I tried changing the 
  <code>var response = x.responseText;</code>, but was unsuccessful.</p>
  
  <p>My question is, what is the correct way to use javascript to parse and process the JSON data, while abiding by the Chrome Extension guidelines?</p>
  
  <p>Any help or guidance would be much appreciated.</p>
  
  <p>Thanks,</p>
  
  <p>Blaine</p>