我正在尝试使用jQuery Mobile在iOS上实现身份验证API。我正在使用jQuery.ajax()
发送帖子请求,但代码失败。
下面给出了代码,我正在使用jQuery Mobile框架和Phonegap for iOS。
此代码有什么问题吗?
是否可以返回哪个HTTP错误代码(例如500,404等)?
function authenticate() {
$.ajax({
url: "https://someurl.com/authenticateUser",
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: JSON.stringify("{\"jsonText\": \"{ \"username\" : \"Test\", \"password\" : \"testing123\" } \"} "),
success: function (result) {
alert(result);
},
error: function (result) {
console.log(result);
}
});
}
当我通过HTML测试代码时 -
<input id="clickMe" type="button" value="Authenticate Me" onclick="authenticate();" />
我得到一个提醒视图说:
index.html
[object Object]
编辑:在阅读了一些评论之后,我现在正在使用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"}