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