Я не могу получить обратный вызов успеха для работы в jQuery ajax-вызове. Следующий код вызывает interpretResponse()
просто отлично, но, конечно, resultJSON
является undefined
:Функция jQuery ajax success callback - как сделать ее анонимной?
var that = this;
jQuery('#fsForm1492441').submit(function(event) {
event.preventDefault();
jQuery.ajax({ type: "POST",
url: "format_result.php",
data: jQuery(this).serialize(),
success: that.interpretResponse(),
dataType: "json"
});
});
function interpretResponse(resultJSON) {
// code here to handle resultJSON
}
Я хочу что-то вроде:
success: function(resultJSON) {
that.interpretResponse(resultJSON);
},
Как следует написано success
обратного вызова?
вместо установки 'dataType: 'json'', вы должны установить заголовок в файле, который вы вызываете,' 'Content-type: application/json''. FAR более надежный, и меньше JS для синтаксического анализа. – PlantTheIdea