4
我读过关于这个问题的所有问题,但并没有设法解决它......jQuery的问题WEBMETHOD
比分类:
public class Score
{
// default constructor
public Score()
{ }
public int TraitID { get; set; }
public double TraitScore { get; set; }
}
该ASPX的WebMethod:
[WebMethod]
public static bool Test(List<Score> scores)
{
return true;
}
jQuery代码:
var scoresList = [{"TraitID":1,"TraitScore":2}, {"TraitID":2,"TraitScore":5}];
$.ajax({
type: "POST",
url: "Tryouts.aspx/Test",
data: "{'scores':" + JSON.stringify(scoresList) + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
if (response.d == true) {
alert("success!!!!!");
}
else {
alert("problem!!!!!!!!!");
}
},
error: function() {
alert("ERROR");
}
});
我不断收到错误:
{"Message":"Cannot convert object of type \u0027System.String\u0027 to type
\u0027System.Collections.Generic.List`1[BusinessLogicLayer.Score]\u0027","StackTrace":" at
System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(Object o, Type type,
JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)\r\n at
System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(Object o, Type type,
JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)\r\n at
System.Web.Script.Services.WebServiceMethodData.StrongTypeParameters(IDictionary`2 rawParams)\r\n
at System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(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"}
谢谢!!!
感谢您的回答,但它不适用于我... – Sash 2011-05-26 17:24:45
是否有错误?它到达WebMethod了吗? – ShaneBlake 2011-05-26 17:31:44
它没有得到WebMethod - 与我的第一个问题一样的错误... – Sash 2011-05-26 17:33:47