我正在使用Rails 3和JQuery 1.4.2并尝试绑定到给定远程表单提交上的ajax:failure回调.回调工作正常,但是,传回的xhr变量似乎以某种方式丢失了responseText属性.
这是我的代码的样子:
_form.html.haml
= form_for(object, :remote => true) do |f|
= form fields and such...
Run Code Online (Sandbox Code Playgroud)
Javascript某个地方......
$('form').livequery('ajax:loading', function() {
// what to do on ajax loading
}).livequery('ajax:success', function(data, status, xhr) {
}).livequery('ajax:failure', function(xhr, status, error) {
alert(xhr.responseText);
});
Run Code Online (Sandbox Code Playgroud)
我基本上是从控制器渲染对象的错误消息,以便我可以在此回调上显示错误通知.奇怪的是我进入了rails.js,第49-51行
error: function (xhr, status, error) {
el.trigger('ajax:failure', [xhr, status, error]);
}
Run Code Online (Sandbox Code Playgroud)
并手动写入控制台responseText,它的工作方式与我期望的一样.
难道我做错了什么?xhr对象如何从rails.js变为我的绑定?