尝试学习在表单上使用AJAX (使用AJAXForm插件),然后用PHP进行处理,并且遇到了很多麻烦。
基本上,我有一个表单,它有很多字段,我想通过AJAX调用某个页面来处理它。这是我的表格:
<form action="" method="post" id="aligned" class='add'>
. . . . .yadda yadda yadda. . . .
<button type='submit' class='btn btn-primary'>Add</button>
</form>在这页的底部,我有:
$(document).ready(function() {
// bind 'myForm' and provide a simple callback function
$('.add').ajaxForm(function() {
alert("Thank you for your comment!");
});
$('.add').ajaxForm({
url: this.href, type:'post',
data: this.serialize()+'&action=update',
success: function(){alert('ok'+responseText.text);},
error: function(){alert('ok'+responseText.text);}
});
}); 第一个ajaxForm函数在提示下工作,所以我一定是在做第二个函数时做错了什么,尽管我试图遵循我在网上找到的不同的例子。
我在PHP页面中没有太多的内容--只是一个简单的“回声”。
(-Do,我需要做一些事情来将它设置为成功/错误(因为我不是,所以它什么都不做)?我的格式错误?-Is responseText.text不是获取回显信息的正确方法?)
发布于 2014-11-05 21:09:36
我在您的代码中看到错误,您需要在函数的签名中添加responseText
success: function(responseText){alert('ok'+responseText.text);},
error: function(responseText){alert('ok'+responseText.text);} https://stackoverflow.com/questions/26766820
复制相似问题