jQuery Ajax submit(Ajax 提交表单)

简单,但应该挺实用的.

JavaScript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//leon.nerr@gmail.com 
//leon.nerr@gmail.com 
function update(){
    var params = {};
    $("input:checked, :text, :hidden, :password,select, textarea").map(function() {
        params[$(this).attr('name')] = $(this).val();
    });
    $.ajax({
        type:"POST", url:"submit.php", data:params, dataType:"json",
        success: function(data){
            //
        },
        error:function(){
            alert('err');
        }
    });
}

Comments (2)

  1. Nerr  / Reply

    呵呵,多谢,这两上方法我还没用过,我空试一下

  2. zeroaction  / Reply

    你好啊!
    其实jquery自身就带有一个serialize()和serializeArray(),可以直接把一个表单里的数据拼接成query字符串或JSON的

Leave a Reply

Allowed Tags - You may use these HTML tags and attributes in your comment.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

 :wink:  :-|  :-x  :twisted:  :)  8-O  :(  :roll:  :-P  :oops:  :-o  :mrgreen:  :lol:  :idea:  :-D  :evil:  :cry:  8)  :arrow:  :-?  :?:  :!:

Pingbacks (0)

› No pingbacks yet.