【问题标题】:$.ajax Call Error while my Call get successfully executed我的呼叫成功执行时 $.ajax 呼叫错误
【发布时间】:2010-10-28 06:28:22
【问题描述】:

我处于无法弄清楚我错在哪里的情况。 我正在使用 jquery 调用 Web 服务。它工作正常,因为它调用 webmethod 完成了操作。但是它调用函数服务在错误子句上失败而不是在 $.ajax 调用中成功

如果服务成功,它应该提醒我“嗨”。但它正在调用 ServiceFailed 函数,但在我输入并使用 $.ajax 调用传递给服务时,数据库中的值会完美更新

我的 j 查询代码闲置

函数 ActionSendRequest() {

        if (globArray.length > 0) {
            alert(globArray.length);
            document.getElementById('lblError').innerHTML = 'Please Wait.....';
            for (var i = 0; i < globArray.length; i++) {
                var Lot = globArray[i];
                var Price = document.getElementById('prc' + globArray[i]).value;
                var Quantity = document.getElementById('qty' + globArray[i]).value;
                $.ajax({
                    type: "POST",
                    url: "../test.asmx/AddModReqSample", 
                    data: "{Lot:'" + Lot + "',Price:'" + Price + "',Quantity:'" + Quantity + "'}", 
                    contentType: "application/json; charset=UTF-8", 
                    dataType: "xml", 
                    processdata: true, 
                    success: function (msg) {
                        ServiceSucceeded(msg);
                    },
                    error: ServiceFailed
                });
            }
        }
    } 
    function ServiceSucceeded(result) {
        alert('hi');
        if (result.d == "Error") {

        }
        else if (result.d == "Successfully") {

        }
    }
    function ServiceFailed(result) {
        document.getElementById('lblError').innerHTML = 'Service call failed: ' + result.status + '' + result.statusText;
    }

而我的 WebService 方法是 fallows

[WebMethod(EnableSession = true)]

public string AddModReqSample(int Lot, decimal Price, decimal Quantity) {

        if (SessionLog.UID != 0)
        {
            return objDataStore.ReqSample(Lot, SessionLog.UID, Quantity,Price);

        }
        else return "Please Login to the System";

} 我得到的最终信息是这样的 服务调用失败:200 OK

【问题讨论】:

    标签: jquery


    【解决方案1】:

    在查看响应和代码更多时间后,我遇到了问题,我的 webmethod 响应为 json 格式,而我正在查看 xml 格式的数据,如您在上面的代码中所见 dataType:“xml”,我将其更改为 json,现在我得到了正确的结果。 谢谢每一位

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-29
      相关资源
      最近更新 更多