Skip to content
This repository has been archived by the owner on Feb 8, 2019. It is now read-only.

Commit

Permalink
Use request.responseType = 'json'. Also remove try/catch. Fixes #9
Browse files Browse the repository at this point in the history
  • Loading branch information
sole committed Apr 25, 2014
1 parent 9ba2b44 commit 0d473ca
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ window.onload = function() {
request = new XMLHttpRequest({ mozSystem: true });

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

request.onerror = function(e) {
var errorMessage = request.error;
Expand All @@ -57,21 +57,17 @@ window.onload = function() {

definitionText.classList.remove('hidden');

try {

var response = JSON.parse(request.responseText);
var response = request.response;
var documents = response.documents;

if(documents.length) {
var doc = response.documents[0];
var text = doc.excerpt;
var title = doc.title;

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


} catch(e) {

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

}

};
Expand Down

0 comments on commit 0d473ca

Please sign in to comment.