我正在尝试使用 jQuery Mobile 在 iOS 上实现身份验证 API。我正在使用 发送发布请求,jQuery.ajax()
但代码失败。
下面给出了代码,我正在使用 jQuery Mobile 框架和 iOS 的 Phonegap。
这段代码有什么问题吗?
是否有可能返回哪个 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"}