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 jQuery's serializeArray.

However I then want the server to respond with the same structure of JSON that was sent and re-load the control values using the provided JSON. I can't find anything in the jQuery documentation that would make this a simple operation.

Am I missing something or do I need to build this myself?


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);
By : Pim Jager

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.

By : Diodeus

If you have PowerShell installed, the command would be

dir -r | select Name, LastWriteTime | sort LastWriteTime -DESC | select -first 1

This way, the script could run as necessary and you could pass the Name (or full path) back into your system for processing.

By : jwmiller5

This video can help you solving your question :)
By: admin