解析 jQuery.ajax 错误响应消息
我通过 jQuery ajax 调用以 JSON 的形式将数据从一个 ASP.NET 页面发布到另一个页面。
我正在模拟这种情况,ajax 调用时出错。如果出现错误,我会收到一条响应消息,并且我需要将此 html 分配给页面上的元素。
这是我在消息中收到的内容:
我有 msg javascript 变量,当通过 Chrome 调试器查找时,它显示它包含我的信息需要responseText
。
如何获取要在页面上显示的responseText 值?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 JavaScript 中,变量名区分大小写。在您的示例中,您尝试访问 msg 对象上的
responseText
字段,但您有一个大写的“R”。试试这个:或者用更好的风格:
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:Or in much better style:
由于它是一个对象,因此使用点符号来访问它,例如 xhr.responseText
Since its an Object use the dot notation to access it like xhr.responseText
您可以在鼠标指针下方的代码中看到 - 仅使用“r”,而不是大写“R”:
You can see in the code just under your mouse pointer - only with "r", not capital "R":
假设您在
msg
中遇到错误assume that u got error in
msg