6

I have a js.erb file where I perform an ajax GET like so:

$.get("<%= j @stored_location %>");

All is well, however my server logs show this:

Processing by XyzController#index as */*

I know that "/" means "any format", and everything is working just fine, so I'm wondering if there's any point in trying to ensure that Rails processes this action explicitly as :js. Do I need to add something to the $.get call? Should I bother?

4

1 回答 1

11

1:你应该打扰吗?

我认为在这些事情上尽可能准确和明确总是一个好习惯。如果您希望能够根据将来的请求时间对相同的 URL 做出不同的回答,您将不得不处理这个问题。所以,是的,你应该打扰。更糟糕的是,你会从中学到新的东西:)

2:如何解决这个问题?

Jquery Get 文档列出了dataType可以传递给调用的参数。因此,例如,如果您希望从服务器返回 JSON,您的请求可能如下所示:

$.get({
  url: "<%= j @stored_location %>",
  data: data,
  success: success,
  dataType: "json"
});

查看文档并确定最适合您的情况。

于 2014-02-17T05:24:19.853 回答