需要一些Jquery /Ajax方面的帮助。
我在一个页面中有多个表单,一旦其中一个表单被单击,它就会将数据发送到post.php ++ disables submit按钮。为此,我使用了以下脚本。
<script>
$(function () {
$('form').on('submit', function (e) {
$.ajax({
type: 'post',
url: 'post.php',
data: $(this).serialize(),
success: function (returnedData ) {
$( '#sidebar' ).load( 'div.php');
}
});
e.preventDefault();
});
});
</script>
<script>
$(document).ready(function () {
$('input[type=submit]').click(function () {
$(this).prop("disabled", true);
$(this).val( "Selected" );
$(this).closest('form').trigger('submit');
});
});
</script>我面临的问题是,除了IE9,它在所有浏览器上都能很好地工作。(它会重复提交数据….)。如何将两个脚本合并为一个脚本?我面临的问题是,除了IE9,它在所有浏览器上都能很好地工作。(它会重复提交数据….)。如何将两个脚本合并为一个脚本?(请注意,我在此页面…中至少有50个表单.)**
发布于 2014-05-07 19:32:28
使用此选项可防止双重提交
<input type="submit" onclick="return false; " />要合并这两个脚本,只需执行以下操作:
<script>
$(function () {
$('input[type=submit]').click(function () {
e.preventDefault();
e.stopPropagation();
$(this).prop("disabled", true);
$(this).val( "Selected" );
$.ajax({
type: 'post',
url: 'post.php',
data: $(this).parents('form:first').serialize(),
success: function (returnedData ) {
$( '#sidebar' ).load( 'div.php');
}
});
});
</script>https://stackoverflow.com/questions/23516361
复制相似问题