【发布时间】:2014-07-20 23:12:24
【问题描述】:
当我尝试这个时,它确实有效
function test() {
debugger;
$.ajax({ url: "http://testweb.com/myAPI.asmx/GetPersonTest",
type: "GET",
contentType: "application/json; charset=utf-8",
data: { userid: 1 },
dataType: "jsonp",
success: function(json) {
alert(json.UserID + ' ' + json.FirstName + ' ' + json.LastName);
},
error: function() {
alert("Hit error fn!");
}
});
}
在同一个 asmx 中,我有另一种方法,如下所示
function Post_test(){
var newURL = window.location.protocol + '//' + window.location.host + '/' + window.location.pathname;
var user = document.getElementById('Username').value;
var email = document.getElementById('email').value;
debugger;
$.ajax({ url: "http://testweb.com/myAPI.asmx/GetPerson",
type: "GET",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ username: user, emailID: email}),
dataType: "jsonp",
success: function(json) {
alert(json.UserID + ' ' + json.FirstName + ' ' + json.LastName);
},
error: function(json) {
alert("Hit error fn!");
}
});
}
此方法插入数据库并返回与 GetPersonTest 相同的结果。但是当我通过 javascript 和 jsonp 调用它时,它会给出 500 服务器错误
当我签入调试器时,它给出了以下错误
jQuery17106155389654450119_1401518867750({"Message":"Invalid web service call, missing value for parameter: \u0027username\u0027.","StackTrace":" at System.Web.Script.Services.WebServiceMethodData.CallMethod(Object target, IDictionary`2 parameters)\r\n at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"});
任何人都可以在下面帮助我。谢谢
方法的头部是
<WebMethod(True)> _
<ScriptMethod(UseHttpGet:=True, ResponseFormat:=WebMessageFormat.Json)> _
Public Function GetPerson(ByVal username As String, ByVal emailID As String) As String
End Function
当我在开发人员工具中检查标题时,它在下面
callback:jQuery17106155389654450119_1401518867750
{"username":"testuser","emailID":"test@test.com"}:
_:1401518889467
Response Headersview source
【问题讨论】:
标签: javascript asp.net web-services jsonp