Reputation: 10509
I am posting data from one ASP.NET page to another via jQuery ajax call in a form of JSON.
I am simulating the situation, where is get an error on ajax call. I get a response message in case of an error and I need to assign this html to an element on the page.
Here is what I get in a message:
I have the msg javascript variable, that, when looked up via Chrome debugger shows me that it contains info I need in responseText
.
How do I get the value of responseText to display on the page?
Upvotes: 8
Views: 17994
Reputation: 3798
<div id='error'></div>
assume that u got error in msg
$('#error').html(msg.responseText)
Upvotes: 1
Reputation: 12742
You can see in the code just under your mouse pointer - only with "r", not capital "R":
msg['responseText']
Upvotes: 2
Reputation: 6302
Since its an Object use the dot notation to access it like xhr.responseText
error: function(xhr, status, error) {
var err = eval("(" + xhr.responseText + ")");
alert(err.Message);
}
Upvotes: 2
Reputation: 36999
In JavaScript variable names are case sensitive. In your example, you were trying to access the responseText
field on the msg object, but you had a capital 'R'. Try this instead:
msg['responseText']
Or in much better style:
msg.responseText
Upvotes: 14