Ajax submits the server data and collates the conversion methods.
Html:
<form id= "FM" name= "FM" action= "" >
<input name= "UserName" type= "text" value= "UserName1"/>
</ Form>
1. The form element turns querystring
2. Strings, JSON converting to each other
var obj = Jquery.parsejson (' {' name ': ' John '} ');
You can use the Jquery-json plug-in to implement transformations, directly referencing the example
var thing = {plugin: ' Jquery-json ', version:2.3};
var encoded = $.tojson (thing);
' {' plugin ': ' Jquery-json ', ' Version ': 2.3} '
var name = $.evaljson (encoded). Plugin;
"Jquery-json"
var version = $.evaljson (encoded). version;
3. Form, Element Name,value array
var arr = $ ("#fm, #UserId"). Serializearray ();
/*[
{name: ' UserName ', Value: ' UserName ' 1 '},
{name: ' UserId ', Value: ' UserId '}
4. Form elements turn to JSON
$.fn.serializeobject = function ()
{
var o = {};
var a = 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 | | '';
}
});
return o;
};
var obj = $ (' form '). SerializeObject ();
/*obj:object
UserId: "UserId1"
UserName: "UserName1"
5. Json2form
$.getjson (' Url_to_file ', function (data) {for
(var i 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",
"Contacts": "Phone"
}
$ (' Div#data '). Loadjson (data);
<div id= "Data" >