/ / Fehler beim Ausführen der Methode jquery $ .getJSON () - jquery, ajax, json

Fehler beim Ausführen der jquery $ .getJSON () -Methode - jquery, ajax, json

Ich entwickle ein Beispiel für ein jQuery-Plugin, das Daten aus einer JSON-Antwort lädt.

Ich weiß nicht warum, aber es ruft nicht die Erfolgsmethode auf. Es geht zur .error () - Methode. Kann mir jemand dabei helfen?

http://www.technicalkeeda.com/demos/load_scroll_content gibt eine korrekte JSON-Antwort zurück.

<script>

$(document).ready(function () {

var jqxhr = $.getJSON("http://www.technicalkeeda.com/demos/load_scroll_content", function(data) {
alert("success");
},"json").success(function() { alert("second success"); })
.error(function(xhr, testStatus, error) {

alert("Error" + xhr.status);
alert("Error" +xhr.response);
alert("Error" +xhr.responseText);

})
.complete(function() { alert("complete"); });
jqxhr.complete(function(){ alert("second complete"); });

});
</script>

Antwort vom Service

[[{"EMPLOYEE_ID":"1","EMPLOYEE_NAME":"Yashwant Chavan"},{"EMPLOYEE_ID":"2","EMPLOYEE_NAME":"Mahesh Diwan"},{"EMPLOYEE_ID":"3","EMPLOYEE_NAME":"Rajesh Limaye"},{"EMPLOYEE_ID":"4","EMPLOYEE_NAME":"Pankaj Patil"}]]

Antworten:

2 für die Antwort № 1

Sie müssen die hinzufügen JSONP Rückrufparameter, wie folgt:

$.getJSON("http://www.technicalkeeda.com/demos/load_scroll_content?callback=?");

Die jQuery-Ajax-Funktion ersetzt die letzte? auf eine zufällige Zeichenfolge wie "jQuery12345" und die Antwort sollte den Wert des Rückrufparameters wie folgt verwenden:

jQuery12345([
{"EMPLOYEE_ID":"1","EMPLOYEE_NAME":"Yashwant Chavan"},
{"EMPLOYEE_ID":"2","EMPLOYEE_NAME":"Mahesh Diwan"}
])

Weitere Informationen zu JSON finden Sie hier: