在提交表单之前加载ajax对话框
Load ajax dialog before form submit
如何使用ajax禁用表单提交?在提交表单之前,用户必须先点击ajax对话框中的按钮。
//on form submit
//I'm using input type submit and not button (as much as possible, I don't want to change that)
$.ajax({
type: "POST",
url: "<?=url::base(TRUE)?>prompt",
data: $('#formname').serialize(),
async: false,
success: function(response){
$("#dialogpromt").html(response);
$("#dialogpromt").dialog({
autoOpen: true,
height: 'auto',
width: '100',
resizable: 'false',
dialogClass: 'dFixed'
});
//onlcick event would change a hidden field to '1'
//works fine
},
});
//Is there a way I can ensure that the dialog above is closed first before the below lines will execute?
if(document.getElementById('submitInd').value == "0")
return false;
else
return true;
提前感谢!
$("Your Submit button Id").click(function (event) {
event.preventDefault(); // this will be used to stop the reloading the page
$.ajax({
type: "POST",
url: "<?=url::base(TRUE)?>prompt",
data: $('#formname').serialize(),
async: false,
beforeSend: function () { /// use beforeSend to open a dialog box
$("#dialogpromt").dialog({
autoOpen: true,
height: 'auto',
width: '100',
resizable: 'false',
dialogClass: 'dFixed'
});
},
success: function (response) {
$("#dialogpromt").html(response);
//tried the if else here, no luck.
//the dialog will just load but the form will still continue to submit
}
});
});
有几种方法可以使按钮不提交。当我开始使用表单时,我学到的是使用span来代替按钮。
一个更好,更简单的方法,因为它允许你保持你的按钮结构,是简单地写
<button type='button'>....</button>
我不确定它到底是做什么的,但是包括type='button
,而不是type='submit'
,这是默认的表单,抑制默认的表单提交动作。
还有其他方法可以使用javascript来改变这一点,比如手动抑制默认操作,甚至不使用表单,而是用'form'类将项目包装在div中,以及大量其他适合您需求的通用方法。
相关文章:
- 如何更改jquerymobile中默认的加载ajax加载程序gif
- 无法在 IE6 和 IE7 上加载 ajax
- 页面刷新后重新加载 ajax 检索到的数据
- 清理在加载 Ajax 内容时添加的 CSS
- jquery选项卡加载Ajax内容
- Grails:多个加载ajax调用,但只有一个打印到控制台
- 如何检测通过JSON数据引用的图像何时加载AJAX
- 加载ajax数据时出现jVectorMap问题
- JQuery在加载ajax时阻止链接工作
- 如何在不重新加载ajax的情况下在datatable上.draw()或添加行
- 替换超链接默认操作以加载 AJAX 请求
- 高图表不使用加载 ajax 的数组进行渲染
- 带有 OnClick 的 jQuery 链接标记 href 需要单击两次才能加载 AJAX
- 悬停两次以加载 ajax
- 获取加载 ajax 的文档信息
- 使用 Jquery 在 AJAX 内部加载 AJAX
- 为什么当页面加载 AJAX 时我的 URL 之间没有空格
- 在当前页面中加载一个新的谷歌地图,加载AJAX
- 当滚动达到 80% 时加载 ajax
- 图像滑块未加载 Ajax 请求