我有一个弹出阴影盒样式的小网络表单。然后提交表单并通过 ajax 发送信息。这在 Firefox 中很有效,但是在 Safari 中,按下提交后,它会关闭影子框,并且似乎只是提交表单(无 ajax)。
按钮和内容的 html 代码...
<div id="booking_box_header"></div>
<div id="booking_box_content">
<div id="booking_box_left">
</div>
<div id="booking_box_right_container">
<form id="booking_form_1" method="post">
<input name="event_id" value="4" type="hidden">
<input name="time_id" value="18" type="hidden">
<input name="booking_email" value="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5d3f313c351d3932303c3433733e3230" rel="noreferrer noopener nofollow">[email protected]</a>" type="hidden">
<div id="booking_box_right">
<input name="booking_name" type="text">
<input name="booking_mobile" type="text">
<div id="ticket_select">
<select name="booking_state" id="booking_state"></select>
// the submit button
<input id="next" value="Next" type="submit">
</div>
</div>
</form>
</div>
相关Jquery代码如下:
$('#booking_form_1').submit(function() {
var booking_email = $('input[name=booking_email]').val();
var event_id = $('input[name=event_id]').val();
var time_id = $('input[name=time_id]').val();
// bring up the loading
$('#booking_box_content').html(loader_img);
// submit the data to the booking form again
$.ajax({
type: 'POST',
url: 'process.php',
cache: false,
data: 'booking_step=1&event_id='+event_id+'&time_id='+time_id+'&booking_email='+booking_email+'',
success: function(data) {
$('#booking_box_content').html(data);
}
});
});
我想知道 safari 是否不喜欢我重新绑定(bind)提交函数,因为它似乎就像我什至没有编写任何 JS 代码一样工作......你觉得怎么样?
最佳答案
我认为你需要添加
return false;
在 ajax 调用之后停止默认提交操作的发生。
这是来自 api 的 EG
$('#target').submit(function() {
alert('Handler for .submit() called.');
return false;
});
关于jquery - 为什么这在 Firefox 中有效,但在 Safari 中无效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4131056/