我有下面的代碼片段中,我想返回值從ajax.but我得到以下異常jQuery的AJAX回報異常(請求格式無效)
請求格式無效
[WebMethod]
[ScriptMethod(ResponseFormat=ResponseFormat.Json)]
public string HelloWorld(string name) {
return "Hello World"+name;
}
$(document).ready(function() {
function checkUser2(user) {
var result;
$.ajax({
type: "POST",
async: false,
url: "WebService.asmx/HelloWorld",
dataType: "json",
contentType:"application/json",
data: { name: user},
success: function (data) {
result = data;
}
});
return result;
}
$("#check").click(function() {
alert(checkUser2("test"));
});
});
編輯
如果爲此有其他的方式,請分享一些鏈接或代碼
現在,我得到這個異常**無效的JSON基元:name ** – 2011-06-01 16:58:18
test with:data:'name ='+ user, – cranberies 2011-06-01 17:03:41
again error again – 2011-06-01 17:10:31