2

I am making jquery ajax call to post data on server and return response from whether completed successfully or not. But I am not able to see response in 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 });
    }
});

here i am not getting any alert but able to see response in 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);
    }
}

where I am missing?

8
  • 1
    have you tried alert(d.response) ? Commented Dec 5, 2013 at 11:22
  • alert(d.response) actually. Commented Dec 5, 2013 at 11:23
  • tried both response.d & d.response but didnt work Commented Dec 5, 2013 at 11:28
  • You are specifying dataType to be application/json and writing text content to response. JSON parser fails to parse your response and hence success is never called Commented Dec 5, 2013 at 11:28
  • You set dataType to json, but write plain text in response. Set dataType to text. Commented Dec 5, 2013 at 11:29

1 Answer 1

3

Use the reponseType as "json" and try response.d. Also add error function to find where exactly the problem occurs

$.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);
   }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.