I read many, many Q questions and the same problem, but I do not have my specific problem (at least I could not find this).
I have a php script that returns a json string
header('Content-Type: application/json'); echo $result;
JSON returned (marked with JSONLint and valid):
{"Announcement":{"ID":1,"Type":1,"Text":"This is a test Albums announcement.","TimeStart":"1969-12-31","TimeEnd":"1969-12-31"}}
And a web jquery script that reads json:
$.ajax({ type : "GET", url : "http://b***s.net/S****s/GetAnnouncements.php?callback=?", data : {get_param : "Announcement"}, dataType : "json", error : function(jqXHR, textStatus, errorThrown) {alert(errorThrown); alert(textStatus);}, success : function(data) {alert('success'); $.each(data, function(index, element) { alert('here'); $("#announcements-list").append("<li><a id='announcements-a-" + element.ID + "' href='#announcement-details'><p>" + element.Type + ": " + element.Text + "</p></a></li>"); $("#announcements-a-" + element.ID).bind('click', function() {Announcements.AnnouncementID = element.ID;}); }); $("#announcements-list").listview('refresh'); } });
success: never called. And error: returns a textStatus of "parsererror" and errorThrown is "Error: jQuery1830649454693285679_1359620502896 was not called"
- I added
callback=? in the url to get around the problem between domains. - I sent
header('Content-Type: application/json'); in php and it returns NO html. - I checked the validity of JSON using JSONLint
- I tried removing
data: "json" as some answers say, but it still returns parsererror - Using jQuery 1.8.3
source share