jQuery帖子请求失败

时间:2013-02-06 00:14:04

标签: jquery cordova jquery-mobile

我正在尝试使用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"}

1 个答案:

答案 0 :(得分:0)

查看返回警报,您已经很难分辨出发生了什么。但是,如果您想知道返回的错误代码,那么您可以尝试this之类的内容。您所依赖的POST请求是否也在同一个域中?

相关问题