window.onload = function() {

  var apiURL = 'https://developer.mozilla.org/search.json?q=';
  var defaultSearchTerm = 'javascript';
  var errorMsg = document.getElementById('error');
  var searchInput = document.getElementById('term');
  var searchButton = document.getElementById('search');
  var definitionText = document.getElementById('definitionText');
  var request = null;
  var translate = document.webL10n.get;

  var form = document.querySelector('form');
  form.addEventListener('submit', function(e) {
      e.preventDefault();
      search();
  }, false);

  search();

  // ---

  function search() {

    // Are we searching already? Then stop that search
    if(request && request.abort) {
      request.abort();
    }


    definitionText.innerHTML = '<p>' + translate('searching') + '</p>';
    errorMsg.classList.add('hidden');


    var term = searchInput.value;
    if(term.length === 0) {
      term = defaultSearchTerm;
    }

    var url = apiURL + term;

    // If you don't set the mozSystem option, you'll get CORS errors (Cross Origin Resource Sharing)
    // You can read more about CORS here: https://developer.mozilla.org/docs/HTTP/Access_control_CORS
    request = new XMLHttpRequest({ mozSystem: true });

    request.open('get', url, true);
    request.responseType = 'application/json';

    request.onerror = function(e) {
      var errorMessage = request.error;
      if(!errorMessage) {
        errorMessage = 'Error while searching';
      }
      showError(errorMessage);
    };

    request.onload = function() {

      definitionText.classList.remove('hidden');
      
      try {

        var response = JSON.parse(request.responseText);
        var doc = response.documents[0];
        var text = doc.excerpt;
        var title = doc.title;

        definitionText.innerHTML = '<h2>' + title + '</h2>' + text;


      } catch(e) {

        definitionText.innerHTML = '<p>' + translate('search_no_results') + '</p>';
        console.log('BOOM', e);

      }

    };

    request.send();

  }


  function showError(text) {
    errorMsg.innerHTML = text;
    errorMsg.classList.remove('hidden');
    definitionText.classList.add('hidden');
  }

};

@@ -1301,27 +1301,15 @@
  = '
-application/
 json';%0A
+
 %0A   
@@ -1597,23 +1597,8 @@
    %0A
-      try %7B%0A%0A  
     
@@ -1618,41 +1618,103 @@
 e = 
-JSON.parse(request.responseText);
+request.response;%0A      var documents = response.documents;%0A      %0A      if(documents.length) %7B
 %0A   
@@ -1887,18 +1887,16 @@
 xt;%0A
-%0A%0A
       %7D 
 catc
@@ -1895,20 +1895,15 @@
   %7D 
-catch(e)
+else
  %7B%0A
-%0A
     
@@ -1986,41 +1986,8 @@
 %3E';%0A
-        console.log('BOOM', e);%0A%0A
     

Use request.responseType = 'json'. Also remove try/catch. Fixes #9