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

Commit 2f4ea9d

Browse files
committed
Check JSON key before action
* Check if a key in the returned JSON object exist before performing an action else return an error. Signed-off-by: Alangi Derick <alangiderick@gmail.com>
1 parent 9a80316 commit 2f4ea9d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

script.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ $(document).ready(function () {
1515
url: url,
1616
dataType: 'jsonp',
1717
success: function(data) {
18-
if(data.parse.title != undefined){
18+
console.log(url);
19+
if(data.hasOwnProperty('parse')){
1920
//Hide default title placeholder and show title after search
2021
$('#title').hide();
2122
document.getElementById('title').innerHTML = data.parse.title;
@@ -25,7 +26,7 @@ $(document).ready(function () {
2526
$('#content').hide();
2627
document.getElementById('content').innerHTML = data.parse.text['*'];
2728
$('#content').show();
28-
} else if(data.error != undefined) {
29+
} else {
2930
$('#title').hide();
3031
document.getElementById('title').innerHTML = "Error Occured :(";
3132
$('#title').show();

0 commit comments

Comments
 (0)