脚本宝典收集整理的这篇文章主要介绍了php – CodeIgniter和AJAX表单提交,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我的问题是表单不会用e.preventDefault()提交;到位,但没有它,表单执行发布到数据库然后刷新页面的常规方法.
这是我的AJAX调用:
$(document).ready(function() { $('form#FeedInput').submIT(function(e) { e.PReventDefault(); $.ajax({ tyPE: "POST",url: "<?PHP echo site_url('dashboard/post_Feed_item'); ?>",data: $('.Feed-input').val(),dataType: "htML",success: function(data){ debugger; $('#Feed-container').prepend(data); },error: function() { alert("Error posting Feed."); } }); }); });
工作代码可以是:
$('form#FeedInput').submit(function(e) { VAR form = $(this); e.preventDefault(); $.ajax({ type: "POST",data: form.serialize(),// <--- THIS IS THE CHANGE dataType: "html",success: function(data){ $('#Feed-container').prepend(data); },error: function() { alert("Error posting Feed."); } }); });
以上是脚本宝典为你收集整理的php – CodeIgniter和AJAX表单提交全部内容,希望文章能够帮你解决php – CodeIgniter和AJAX表单提交所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。