我正在尝试在叠加层中呈现一个表单。表单是通过 ajax 加载的。这一切都在 Firefox 3.x 上运行良好。
但在 Safari 5.0(5533.16) 上,覆盖显示但不发出 ajax 请求,而是发出 html 请求。
这是我在 js 中配置它的方法,然后在 document.ready 上调用 ModalPostForm.init();
馅饼 - http://pastie.org/1196064
var ModalPostForm = {
init: function(){
$("a[rel='#post_overlay']").each(function(){
//alert($(this).attr('href'));
$(this).overlay({
closeOnClick: false,
target: '#post_overlay',
fixed: false,
onBeforeLoad: function() {
// grab wrapper element inside content
var wrap = this.getOverlay().find(".contentWrap");
// load the page specified in the trigger
wrap.load(this.getTrigger().attr("href"));
},
onLoad: function() {
setTimeout("configurePostForm(200, 1000, 150)", 500);
},
onClose: function() {
$('.contentWrap').empty();
}
});
});
},
close: function(){
$("a[rel='#post_overlay']").each(function(){
var ol = $(this).data("overlay");
if(ol.isOpened()){
ol.close();
}
});
}
};
这是我的html
<div id="post_overlay" class="new-post-overlay span-12" style="top: 54.3px; left: 429px; position: absolute; display: none;"><a class="close"></a>
<div style="display: none;" id="form_loading" class="">
<div class="loading-inner-center"></div>
</div>
<div id="" class="contentWrap"></div>
</div>
为什么发出 html 请求?
谢谢
更新
如果我在我的控制器操作中删除我的 rails respond_to 块中的 format.html 块,这就会消失。
虽然问题仍然是为什么它发送一个 html 请求或者为什么 rails 认为它是一个 html 请求。对于确实不能做js的浏览器,我宁愿不删除那个块。
导致问题的新动作
respond_to do |format|
# format.html # new.html.erb
format.js {
}
# format.xml { render :xml => @post }
end
也导致问题的编辑操作,新和编辑恰好是“获取”方法。
# format.html {
# if @edit
# #
# setup_post_items(true)
# else
# flash[:error] = 'Sorry no further edits, Post has already been approved.'
# redirect_back_or_default root_url
# end
# }
format.js {
if !@edit
flash[:error] = 'Sorry no further edits, Post has already been approved.'
end
}