If you can automate the two-way conversion of objects (that is, you can convert objects into forms and directly convert forms into objects ). Objects in JavaScript are tough.
(Flexibility), with the code can modify the object members at any time. You can easily bind fields on the client using Js. The client can use the same javascrui.
Processing. For example:
VaR person = {
Name: 'lisq ',
Birthday: '20140901'
}
<Form ID = "formperson">
<Input name = "name"/>
<Input name = "Birthplace"/>
</Form>
<SCRIPT>
For (var p in person ){
$ (P). value = person [p];
}
</SCRIPT>
The submission form is also changed from the traditional form. Submit () to, convert the form to the JSON format first, and then submit the form. The Code is as follows:
<SCRIPT>
VaR P = formperson. serialize (true)
VaR paras = 'o = '+ P. tojsonstring ()
Request (URL, paras, function (){
Alert ('saved successfully! ')
})
</SCRIPT>
Server
The Field Obtained by the server is only O, not the previous name, birthplace. O is the converted string {Name:
'Lisq', birthday: '000000'}. The server performs a JSON-to-C # object conversion. Person P =
JSON. serialize (request ["O"], typeof (person), if the data access layer has a good implementation, then add a line of code to achieve p. save () (see nhib.pdf ).