Modify JSON received and POST back update

南笙酒味 提交于 2019-12-11 23:27:10

问题


Looking for a starting point. I'm getting my data (via json) for a JQM page. I need to be able to edit any of the returned result fields and UPDATE the database via .post json.

My thought is to iterate through the json array, make changes and post json array back, should I be populating text-boxes in the initial load and then creating separate array?

$.getJSON('JSON_MDB.php',
    function (data) {  
        // data is now JSON object instantiated from retrieved info
        $.each( data, function ( i, val ) {

            ($('<div>')
            .attr({
                'data-role': 'collapsible',
                'data-content-theme': 'c',
                'data-collapsed': 'true',
                'id': 'cResults'
            })
            .html('<h4>' + this.lastName + ', ' + this.firstName + '</h4><ul data-role="listview" data-filter="true" data-filter-placeholder="Search Choices..." data-inset="true" id="makecollapsibleul"><li>' 
            + 'FDID: ' + this.FDID + '</li><li>'
            + 'Choice 1: ' + this.C1 + '</li><li>' 
            + 'Choice 2: ' + this.C2 + '</li><li>' 
            + 'Choice 3: ' + this.C3 + '</li><li>' 
            + 'Choice 4: ' + this.C4 + '</li><li>' 
            + 'Choice 5: ' + this.C5 + '</li><li>' 
            + 'Choice 6: ' + this.C6 + '</li><li>' 
            + 'IP: ' + this.IPADDRESS + '</li><li>' 
            + 'Pick Date: ' + this.PICKDATE + '</li></ul>'
            ))
            .appendTo('#primary');

            $('#makecollapsible').collapsibleset().trigger('create');
            $.mobile.hidePageLoadingMsg();

        });
    }
); 

HTML:

<div data-role="page" id="main">      
    <div data-role="header">         
        <h1>MCFRSIT JSON DATA</h1>     
    </div><!-- /header -->      

    <div data-role="content">
        <ul data-role="listview" id="outer-ul">
            <li>  
                <div data-role="collapsible">
                    <h4>Submitted Choices</h4> 
                    <ul data-role="listview" data-inset="true" data-filter="true" id="makecollapsible">
                        <!-- AJAX CONTENT -->
                    </ul>
                </div>
            </li>
        </ul>           
    </div><!-- /content -->      

    <div data-role="footer">              
    </div>

</div><!-- /page -->     

来源:https://stackoverflow.com/questions/19320309/modify-json-received-and-post-back-update

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!