我试图用jQuery和JSON执行一些基本操作.目前,jQuery难以接受来自play framework应用程序的JSON响应.下面是仍然产生错误的代码的简化版本.
$.ajax({
type: 'POST',
url: "@{FrontEnd.isUsernameAvailable()}",
data: "name=thisnameisavailable",
cache: false,
success: function(data) {
console.log("Success... ");
},
error: function(jqXHR, textStatus, errorThrown) {
console.log("Error... " + textStatus + " " + errorThrown);
},
dataType: 'json'
});
始终触发错误回调.它会显示
Error... parsererror jQuery15001997238997904205_1298484897373 was not called
Inspecting the returned JSON through Firebug shows no errors and various JSON lint tools also validate. Changing dataType to "text" makes success be called. But I am trying to use the isUsernameAvailable call as part of jQuery validation plugin so I need it to return valid JSON.