你如何覆盖现有的HTML表单使用jquery发布的形式? [英] How do you override an existing html form to use jquery to post the form?

查看:200
本文介绍了你如何覆盖现有的HTML表单使用jquery发布的形式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的形式,我现在回发到服务器,以更新的绰号。什么jQuery的code我加入(不改变的形式),这样的页面不会刷新,而是jQuery将在后台发布表单,然后弹出包含答复从服务器传回的警报消息?

 <形式方法=邮报行动=htt​​p://www.myserver.com/update_nicknameNAME =输入>
    快速的形式来测试update_nickname:LT; BR>
    新的绰号:LT;输入类型=文字值=BigJoeNAME =newNickname>< BR>
    <输入类型=提交值=提交>
< /形式GT;

<脚本SRC =jQuery的-1.4.2.min.js类型=文/ JavaScript的> < / SCRIPT>
 

解决方案

尝试阅读。

  $(形式)。递交(函数(五){
    变种形式= $(本);
    $阿贾克斯({
         网址:form.attr(行动),
         类型:form.attr(方法),
         数据:form.serialize(),//数据提交
         成功:函数(响应){
            警报(响应); //你喜欢用什么样的反应
         }
    });
    返回false;
 });
 

I have a simple form that I am currently posting back to the server to update a nickname. What jquery code do I add (without changing the form) so that the page will not refresh, but instead jquery will post the form in the background and then pop up an alert message containing the reply back from the server?

<form method="post" action="http://www.myserver.com/update_nickname" name="input">
    Quick form to test update_nickname:<br>
    New nickname:<input type="text" value="BigJoe" name="newNickname"><br>
    <input type="submit" value="Submit">
</form>

<script src="jquery-1.4.2.min.js" type="text/javascript"> </script>

解决方案

try reading this.

or

$("form").submit(function(e){
    var form = $(this);
    $.ajax({ 
         url   : form.attr('action'),
         type  : form.attr('method'),
         data  : form.serialize(), // data to be submitted
         success: function(response){
            alert(response); // do what you like with the response
         }
    });
    return false;
 });

这篇关于你如何覆盖现有的HTML表单使用jquery发布的形式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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