我一直在尝试使用 jQuery Mobile 向 Web 服务(用 .NET 编写)发送 POST 请求。我正在使用 jQuery Mobile 和 iOS 的 PhoneGap 并在 XCode 中编写代码。
这是我正在运行的代码 -
var param = "{\"jsonText\": \"{ \"username\" : \"Test\", \"password\" : \"testing123\" } \"} ";
console.log(param)
$.ajax({
url: "https://example.asmx/authenticateUser",
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
data:JSON.stringify(param),
success: function(result){
console.log(result);
},
error: function(result){
console.log(result);
}
});
这给了我以下错误-
{"readyState":4,"responseText":"{\"Message\":\"Cannot convert object of type \\u0027System.String\\u0027 to type
\\u0027System.Collections.Generic.IDictionary`2[System.String,System.Object]\\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.Serialization.ObjectConverter.ConvertObjectToType(Object o, Type type, JavaScriptSerializer serializer)\\r\\n at
System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)\\r\\n at
System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String input)\\r\\n
at System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext context, JavaScriptSerializer serializer)\\r\\n
at System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData, HttpContext context)\\r\\n
at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData
methodData)\",\"ExceptionType\":\"System.InvalidOperationException\"}","status":500,"statusText":"Internal Server Error"}
请帮忙。