Skip to content
This repository was archived by the owner on Jun 18, 2021. It is now read-only.

Commit

Permalink
Check JSON key before action
Browse files Browse the repository at this point in the history
* Check if a key in the returned JSON object exist
  before performing an action else return an error.

Signed-off-by: Alangi Derick <[email protected]>
  • Loading branch information
xSavitar committed May 13, 2017
1 parent 9a80316 commit 2f4ea9d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ $(document).ready(function () {
url: url,
dataType: 'jsonp',
success: function(data) {
if(data.parse.title != undefined){
console.log(url);
if(data.hasOwnProperty('parse')){
//Hide default title placeholder and show title after search
$('#title').hide();
document.getElementById('title').innerHTML = data.parse.title;
Expand All @@ -25,7 +26,7 @@ $(document).ready(function () {
$('#content').hide();
document.getElementById('content').innerHTML = data.parse.text['*'];
$('#content').show();
} else if(data.error != undefined) {
} else {
$('#title').hide();
document.getElementById('title').innerHTML = "Error Occured :(";
$('#title').show();
Expand Down

0 comments on commit 2f4ea9d

Please sign in to comment.