大佬教程收集整理的这篇文章主要介绍了jquery:表单中的ajax POST – 阻止在ajax调用上提交表单,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
jQuery.ajax({ type: "POST",url: "my_custom/url",dataType: "html",data: {"text": jQuery("#edit-body").html() },success: function(result){ console.log(result); } });
我可以通过在控制台中执行它来复制它,但我将其附加到表单内的按钮单击功能.在POST ajax调用上有关阻止表单提交的任何提示?
这是所要求的完整代码
jQuery("#edit-body").before('<div id="proofread_bot-button-holder"><button type="button" id="proofread_bot-submit" onclick="return false;">check with Proofread Bot</button></div>'); jQuery("#proofread_bot-submit").click(function(event){ event.preventDefault(); jQuery("#proofread_bot-button-holder").append("<img id=\"proofread_bot_throbber\" src=\"sites/all/modules/proofread_bot/images/throbber.gif\" />"); jQuery.ajax({ type: "POST",url: "proofread_bot/check",data: {"text": jQuery("#edit-' . variable_get('proofread_bot_field') . '").html() },success: function(proofread_result){ jQuery("#proofread_bot-submit").after(proofread_result); jQuery("#proofread_bot_throbber").remove(); } }); });
$("formSELEctor").bind('submit',function (E) { var isValid = someYourFunctiontocheckIfFormIsValid(); if (!isValid) { e.preventDefault(); return false; } else { jQuery.ajax({ type: "POST",data: { "text": jQuery("#edit-body").html() },success: function (result) { console.log(result); } }); e.preventDefault(); return false; } });
通过电话
e.preventDefault(); return false;
您可以防止发生同步回发.
更新:如果您不想覆盖表单提交,也许您可以将您的按钮放在表单标签之外(如果需要,您可以使用css调整位置)?
以上是大佬教程为你收集整理的jquery:表单中的ajax POST – 阻止在ajax调用上提交表单全部内容,希望文章能够帮你解决jquery:表单中的ajax POST – 阻止在ajax调用上提交表单所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。