我的控制器会生成常规的html,mobile_fu和javascript:
respond_to do |format| format.html { render :action => "full", :layout => "application" and return } format.mobile { render :action => "full", :layout => "application" and return } format.js { render :partial => "content", :layout => false and return } end
常规html呈现正常,使用网站的html版本中的AJAX工作正常,但在移动浏览器上使用AJAX似乎总是呈现format.mobile块。我将jQuery绑定到按钮的click事件时使用jQuery,我在iPhone上的测试总是最终呈现上面的format.mobile块。
$.ajax({
beforeSend : function(request) { request.setRequestHeader("Accept", "text/javascript"); },
success : function(response) {
$("#content").append(response);
},
type : 'GET',
url : url, //set somewhere else
data : data //set somewhere else
});
jQuery是否没有捕获点击事件(iPhone怪癖?)或者mobile_fu是否负责并且在这里有点霸道?有人已经解决了这个问题,或者看到我错过了什么?
答案 0 :(得分:3)
查看the code的mobile_fu表明,任何进入的移动设备都将设置为移动设备。将第73行更改为类似的内容可能有效:
if is_mobile_device? && !request.xhr?
答案 1 :(得分:0)
万一其他人发现这一点,如果你有不同的移动设备javascript,你可以这样做:
format.mobile {render :content_type => "application/javascript"}
(把你的js放在action.mobile.rjs
)