0

I am using a JQuery in an MVC appliaction post that is erroring out, is there someway to tell what the error is?

Example code -

    $.post("/Path/Action", form, function (returnHtml) {

        //do stuff

    }).error(function () { alert("error"); });

I have attached the ".error" call but that doesn't tell me the cause of the error. Thanks!

3
  • Did you look at the arguments in the function? Commented Oct 4, 2012 at 18:43
  • You mean the "returnHtml"? I put an alert in the "//do stuff" section, but it never make it in there. Commented Oct 4, 2012 at 18:47
  • No in the function in the error. Commented Oct 4, 2012 at 18:53

3 Answers 3

1
.error( function (jqXHR, status, error) {
    alert(jqXHR);
    alert(status),
    alert(error);
 })
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks user1026361! I used your answer.
No Problem! I took the answer straight from jquery.com which is an excellent resource for this library!
1
$.ajax({  
    type: 'POST',  
    url: '/Path/Action',  
    data: form,  
    success: function (data) {  
        console.debug(data);  
    },  
    error: function (data) {  
        console.debug(data);  
    }  
}); 

2 Comments

That is one way to make the call, but not what the OP asked for.
Thanks webdeveloper! I will probably use your style of call in the future!
1

Hopefully you debugged it on your own based on my comment, but you can get the info this way

$.post("/error/").error( function(xhrObject,statusName,statusText) {
    console.log(xhrObject,statusName,statusText);  //Passed in info via arguments
    console.log(xhrObject.status);  //get the status code via the xhr object
});​

jsFiddle example

1 Comment

I used user1026361's solution, but Thanks epascarello!

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.