通过Ajax请求的HTML表单提交? [英] html form submission via an ajax request?

查看:202
本文介绍了通过Ajax请求的HTML表单提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  

可能重复:
   jQuery的AJAX提交表单

我有一个网页A的一种形式,而不是我发布到一个新的页面,是有办法,我可以做的onsubmit Ajax请求它呢?我想使网页能在结果加载到一个div。

我知道如何写剧本的排序的电话,但我不知道如果我有手写或者,如果有可能把所有的表单信息并发送,而不必code这一切为的属性。我想我可能只是做一些有点像件事:的onClick,后期的形式,但返回的结果为一个div

思考?想法?

解决方案

  $。阿贾克斯({
 网址:'的mypage.html,
 成功:功能(数据){
    $('。结果')的HTML(数据)。
 },
 错误:函数(){
   警报(失败);
 }
});
 

然后你有一个div:

 < D​​IV CLASS =结果> < / DIV>
 

这会自动填充你的阿贾克斯后的结果。

http://api.jquery.com/jQuery.post/

另请参阅相关的问题吨: jQuery的检查ajax的帖子成功

Possible Duplicate:
jQuery AJAX submit form

I have a form on a page A, and instead of me posting to a new page, is there a way that i can do onSubmit ajax request it instead? I want to make the page to be able to load in the result into a div.

I know how to write the script for the call sort of, but i wasn't sure if i had to hand write it or it if was possible to take all the form information and send it without having to code it all into the attributes. i was thinking I could just do some sort of thing like: onClick, post form but return results into a div.

Thoughts? Ideas?

解决方案

$.ajax({
 url: 'mypage.html',
 success: function(data){
    $('.result').html(data);
 },
 error: function(){
   alert('failure');
 }
});

Then you have a div:

<div class="result"> </div>

This will automatically populate with the result of your ajax post.

http://api.jquery.com/jQuery.post/

Also see TONS of related questions: Jquery checking success of ajax post

这篇关于通过Ajax请求的HTML表单提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆