Ajax submits server data and collates the conversion method.
Html:
<form id="FM"Name="FM"action=""> <input name="UserName"Type="text"Value="UserName1"/> </form> <input name="UserId"Id="UserId"Type="text"Value="UserId1"/>
1. Form element Turn QueryString
var q = $ ('#fm, #UserId'//q = username=username1&userid=userid1
2. Strings, JSON converts each other
var obj = Jquery.parsejson ('{' name ': ' John '}'" John" );
You can use the Jquery-json plug-in to implement conversions, directly referencing examples
var thing = {plugin: " jquery-json , Version: 2.3 Span style= "color: #000000;" >}; var encoded = $.tojson (thing); // "{" plugin ":" Jquery-json "," Version ": 2.3} ' var name = $.evaljson (encoded). Plugin; // "Jquery-json" var version = $.evaljson (encoded). version; // 2.3
3. Form, element to Name,value array
var arr = $ ("#fm, #UserId"). Serializearray (); /* [ {name: ' UserName ', Value: ' "UserName" 1 '}, {name: ' userid ', Value: ' UserID '} * /
4. Form element to JSON
$.fn.serializeobject =function () {varo = {}; varA = This. Serializearray (); $.each (A, function () {if(o[ This. Name]!==undefined) { if(!o[ This. Name].push) {o[ This. name] = [o[ This. Name]]; } o[ This. Name].push ( This. value | |"'); } Else{o[ This. Name] = This. value | |"'; } }); returno;};varobj = $ ('form'). SerializeObject ();/*Obj:objectuserid: "UserId1" UserName: "UserName1" __proto__: Object*/
5. Json2form
$.getjson ('url_to_file', function (data) { for (var in data) { $ ('input[name=''+i+'"]' ). Val (Data[i]);} }
Google has found a more powerful plugin in the process http://code.google.com/p/jquery-load-json/
data = { "Name":"Emkay Entertainments", "Address":"Nobel House, Regent Centre", " Contact":"Phone" } $('Div#data'). Loadjson (data); <div id="Data"> "Name">emkay entertainments for="Address">Address:</label> <span id="Address">nobel House, Regent centre</span> <label for=" Contact">contact by:</label> <span id=" Contact">Phone</span> </div>
Live demo:http://jquery-load-json.googlecode.com/svn/trunk/edit.html?id=
The Ajax commit parameter is to be aware of the type of the commit parameter. such as the Easyui grid parameter can only be JSON, does not support querystring
Constructs Ajax parameters, TABLE element json transforms each other