jQuery的 - 发送一个形式异步 [英] jQuery - Send a form asynchronously
本文介绍了jQuery的 - 发送一个形式异步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表格,如:
<形式的行动=???方法='后'的名字='接触'>
<输入类型=文本级=inputContactNAME =mittente/>
< TextArea类=textContactNAME =SMEX>< / textarea的>
<输入类型=提交值=发送/>
< / DIV>
< /形式GT;
我想异步发送这些数据,trought jQuery函数 $。阿贾克斯
。
编辑:用的解决方案:
<表格名称='联系形式'>
<输入类型=文本级=inputContactNAME =mittente/>
< TextArea类=textContactNAME =SMEX>< / textarea的>
<输入类型=提交值=发送/>
< /形式GT;
<脚本类型=文/ JavaScript的>
$(文件)。就绪(函数(){
$('形式[名称=联系形式])。递交(函数(五){
即preventDefault();
$阿贾克斯({
键入:POST,
缓存:假的,
网址:./ajax/header_ajax.php,
数据:'ID = header_contact_send&功放;+ $(本).serialize()
成功:函数(MSG){
$(#boxContentId)HTML(MSG)。
}
});
});
});
< / SCRIPT>
解决方案
$('形式[名称=联系方式])。递交(函数(){
//也许表明负载指示灯...
$。员额($(本).attr(行动),$(本).serialize()函数(RES){
//做一些与响应`res`
执行console.log(RES);
//不要忘了隐藏加载指示灯!
});
返回false; // prevent默认操作
});
请参阅:
I have a form such as :
<form action='???' method='post' name='contact'>
<input type="text" class="inputContact" name="mittente" />
<textarea class="textContact" name="smex"></textarea>
<input type="submit" value="Send" />
</div>
</form>
I'd like to send these data asynchronously, trought jQuery function $.ajax
.
EDIT :with solution :
<form name='contactForm'>
<input type="text" class="inputContact" name="mittente" />
<textarea class="textContact" name="smex"></textarea>
<input type="submit" value="Send" />
</form>
<script type="text/javascript">
$(document).ready(function() {
$('form[name=contactForm]').submit(function(e){
e.preventDefault();
$.ajax({
type: 'POST',
cache: false,
url: './ajax/header_ajax.php',
data: 'id=header_contact_send&'+$(this).serialize(),
success: function(msg) {
$("#boxContentId").html(msg);
}
});
});
});
</script>
解决方案
$('form[name=contact]').submit(function(){
// Maybe show a loading indicator...
$.post($(this).attr('action'), $(this).serialize(), function(res){
// Do something with the response `res`
console.log(res);
// Don't forget to hide the loading indicator!
});
return false; // prevent default action
});
See:
这篇关于jQuery的 - 发送一个形式异步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文