Reputation: 37
I wrote this code:
(function($) {
var url = 'http://surfujpametno.roditelji.me/2014/01/23/surfujpametno-aplikacija-za- android/?json=get_all_posts&callback=?';
$.ajax({
type: 'GET',
url: url,
async: false,
jsonpCallback: 'callback',
contentType: "application/json",
dataType: 'jsonp',
success: function(json) {
console.log(json.status);
console.log(json);
try{
json = $.parseJSON(json);
alert(json);
}catch(e){
alert('invalid');
}
},
error: function(e) {
console.log(e.message);
}
});
})(jQuery);
http://surfujpametno.roditelji.me/2014/01/23/surfujpametno-aplikacija-za-android/?json=get_all_posts&callback=? That is JSON url
I get 'Invalid'... If I remove try and catch i get this error: http://prntscr.com/2sf8bd
Upvotes: 1
Views: 83
Reputation: 22711
Try this, Removed $.parseJSON
, because of dataType: 'jsonp',
already defined
(function($) {
var url = 'http://surfujpametno.roditelji.me/2014/01/23/surfujpametno-aplikacija-za-android/?json=get_all_posts&callback=?';
$.ajax({
type: 'GET',
url: url,
async: false,
jsonpCallback: 'callback',
contentType: "application/json",
dataType: 'jsonp',
success: function(json) {
console.log(json.status);
console.log(json);
},
error: function(e) {
console.log(e.message);
}
});
})(jQuery);
Upvotes: 1
Reputation: 66
As Paulloz indicated your json
is already a JSON object: JSfiddle without parse and alert: http://jsfiddle.net/Skadi2k3/cKUD7/
Upvotes: 0