Skip to content Skip to sidebar Skip to footer

Loading HTML Controls From JSON In JQuery (that Is, Reverse Of Ajax SerialiseArray)

I would like to take a set of controls (INPUT, SELECT, TEXTAREA) which are contained within a DIV and send their values as JSON via Ajax to a server. This is easy enough with jQue

Solution 1:

why not just have the server send back in the same: controlname:value structure and then read that out in jQuery and use something like:

$("*[name='" + controlname + "']").val( value);

Or even easier: controlID:value

$("#" + controlID).val( value);

Solution 2:

Form controls are not bound to JSON data.

The JSON data could be intended for any purpose, so you'll have to build a function to take the JSON result and fiddle with the form elements yourself.

Forms are too complex to expect jQuery to handle this natively. In the past I've written frameworks to build forms from XML/JSON-based definitions and to handle the data transport using the same. It's not all that hard to do yourself, but it's not something built-in.

I took a quick peek through the plug-ins and didn't notice anything that specifically does that either, although it does sound like a good idea. It sounds more like something that would be supported though Ext.js.


Post a Comment for "Loading HTML Controls From JSON In JQuery (that Is, Reverse Of Ajax SerialiseArray)"