应用程序 - 2(Java 和 Rails)
导轨 - 3.0.3
红宝石 - 1.8.7
客户端 - 使用来自 Java 应用程序的 Jquery 进行 Ajax 调用
Firebug - 显示它实际上是一个 Ajax XHR 请求(XHR 选项卡)
服务器 - Rails - request.xhr?错误的
ajax 响应缺少任何 gem (仅来自 java pp 的 ajax 请求)
我的宝石清单如下:
abstract (1.0.0)
actionmailer (3.0.3)
actionpack (3.0.3)
activemodel (3.0.3)
activerecord (3.0.3)
activeresource (3.0.3)
activesupport (3.0.3)
arel (2.0.4)
builder (2.1.2)
bundler (1.3.4)
cgi_multipart_eof_fix (2.5.0)
columnize (0.3.6)
crack (0.1.8)
daemons (1.1.0)
delayed_job (2.1.2)
erubis (2.6.6)
fastthread (1.0.1)
gem_plugin (0.2.3)
hoptoad_notifier (2.3.12)
httparty (0.6.1)
i18n (0.4.2)
linecache (0.46)
mail (2.2.10)
mime-types (1.16)
mongrel (1.1.5)
mysql2 (0.2.6)
nokogiri (1.4.4)
polyglot (0.3.1)
rack (1.2.1)
rack-mount (0.6.13)
rack-test (0.5.6)
rails (3.0.3)
railties (3.0.3)
rake (0.8.7)
rbx-require-relative (0.0.9)
ruby-debug (0.10.4)
ruby-debug-base (0.10.4)
ruby-xslt (0.9.7)
rubygems-bundler (1.1.1)
rubyzip (0.9.4)
rvm (1.11.3.6)
thor (0.14.6)
treetop (1.4.9)
tzinfo (0.3.23)
xml-simple (1.0.12)
我的控制器代码是
def index
if request.xhr?
logger.debug " Ajax request yes"
else
logger.debug " Ajax request false"
end
respond_to do |format|
format.html
format.js
end
end
jQuery代码是:
$.ajax({
type: "GET",
url:"someurl"
cache:false,
success: function(data) {
alert('success');
},
error: function(jqXHR, textStatus, errorThrown){
alert(jqXHR.responseText);
}
服务器日志是
Started GET "/mozart_content?id=phyp10084_sa102&dt=20130704132018&api=a3aee3fa-567e-11df-be64-7779fa786bb0&sign=WBCbzBY0GDAP6mQVLxcFZX-ES10%3D" for 192.168.42.27 at Thu Jul 04 18:49:44 +0530 2013
Processing by MozartContentController#index as HTML
Parameters: {"sign"=>"WBCbzBY0GDAP6mQVLxcFZX-ES10=", "api"=>"a3aee3fa-567e-11df-be64-7779fa786bb0", "dt"=>"20130704132018", "id"=>"phyp10084_sa102"}
Ajax request false
Rendered mozart_content/index.html.erb within layouts/application (149.3ms)
Completed 200 OK in 155ms (Views: 154.3ms | ActiveRecord: 0.0ms)