我正在进行jquery ajax调用以将数据发布到服务器上,并从是否成功完成返回响应。但是我无法在js中看到响应。

js:

$.ajax({
    url: 'ajaxExecute.aspx/CAO2',
    data: strRequest,
    dataType: "json",
    contentType: "application/json",
    cache: false,
    context: document.body,
    type: 'POST',
    success: function (response) {
        alert(response);
        window.parent.$('#divDialog').dialog('close');
        window.parent.$('#divDialog').dialog('destroy');
        window.parent.$('#divDialog').html(response);
        window.parent.$('#divDialog').attr('title', 'Error');
        window.parent.$('#divDialog').dialog({ show: "blind", modal: true, dialogClass: 'alert', zIndex: 99999, resizable: false, draggable: false });
    }
});


在这里,我没有收到任何警报,但可以在Chrome -> Inspect Element -> Network -> Response中看到响应

cs

[WebMethod]
public static void CAO2(string Guardian, string CIFID, string EmploymentType)
{
    try
    {
        if (Guardian != "" && CIFID != "" && EmploymentType != "" )
        {
            if (Generix.putCustomerDetailsPart2(Guardian,CIFID,EmploymentType)) // Will Create SQL Query And Execute on Database
            {
                HttpContext.Current.Response.Write("Information Submitted Successfuly..!!<br/><br/>Please Visit Your Nearest Branch...");
            }
            else
            {
                HttpContext.Current.Response.Write("Error Occurred While Processing Information..!!<br/><br/>Please Try Again...");
            }
        }
        else
        {
            HttpContext.Current.Response.Write("Missing Information..!!");
        }
    }
    catch (Exception xObj)
    {
        HttpContext.Current.Response.Write("ERROR: " + xObj.Message);
    }
}


我在哪里失踪?

最佳答案

将reponseType用作“ json”,然后尝试response.d。还添加错误功能以查找问题出在哪里

$.ajax({
   url: 'ajaxExecute.aspx/CAO2',
   data: strRequest,
   dataType: "json",
   contentType: "application/json",
   responseType:"json",
   cache: false,
   context: document.body,
   type: 'POST',
   success: function (response) {
    alert(response.d);
   },
   error: function(xhr) {
    alert(xhr.responseText);
   }
});

10-05 20:28
查看更多