数据远程= "true" on( "ajax:complete"不起作用



这是我的rails html。erb页

<a data-remote="true" data-type="json" href="/project/4/request_access">Request Access</a>

这是在我的javascript在同一页

$(document).ready(function() {
  $("body").on("ajax:complete", function(e) {
    console.log("Got Ajax complete: ");
    console.log(e);
  });
}

我在我的终端上得到一个200的成功。我在正在寻找的响应中获得数据,但从未调用控制台日志。我之前更具体地使用id,但去了'body'只是为了捕捉所有内容。还是不行。怎么了?

网络响应:

General
  Request Method:GET
  Status Code:200 OK
Request Headers
  Accept:application/json, text/javascript, */*; q=0.01
  X-Requested-With:XMLHttpRequest
Response
  {"success":"You have been added to Y-find"}

您可以这样尝试:

<a id="remote" data-remote="true" data-type="json" href="/project/4/request_access">Request Access</a>

$(document).ready(function() {
    $("#remote").on("ajax:success", function (e, data, status, xhr) {
        console.log( xhr.responseText )
     });
    $("#remote").on("ajax:error", function(e, xhr, status, error) {
        console.log ("ERROR");
    });
});

最新更新