admin管理员组文章数量:1429515
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?
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?
Share Improve this question edited Apr 1, 2011 at 21:10 Peter Mortensen 31.6k22 gold badges110 silver badges133 bronze badges asked Dec 29, 2008 at 15:32 AnthonyWJonesAnthonyWJones 189k35 gold badges235 silver badges307 bronze badges2 Answers
Reset to default 4why 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);
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 plex 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.
本文标签:
版权声明:本文标题:javascript - Loading HTML controls from JSON in jQuery (that is, reverse of Ajax serialiseArray) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745527902a2661922.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论