你如何覆盖现有的HTML表单使用jquery发布的形式?表单、形式、HTML、jquery

2023-09-11 00:48:08 作者:你的名字我的心事

我有一个简单的形式,我现在回发到服务器,以更新的绰号。什么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;
 });
 

怎么使用jquery验证表单

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;
 });