简体   繁体   中英

jQuery is stripping out HTML, I don't know why

This code works perfectly, but when I will put the final HTML, only appears the values, but the HTML not. What is happening??

        $('[role=query-username]').live( 'click', function() {
            var output = "<table>";
            $.post( 
                    '/action/jsonUserInformation.php', 
                    'username=' + $('#username').val(), 
                    function(data) {
                        $('#user_results').html('');
                        var data_json = $.parseJSON( data );
                        $.each( data_json, function() {

                            $.each( this, function(i, v) 
                                    {
                                        output = output +  "<tr><td>" + i + "</td><td>" + v + "</td></tr>";
                                    });
                            output = output + "</table>";

                        });

                        $('#user_results').html( output );
                    });
            });

Result Output is: code37username_code41account_passwordfb8465e62c8b2bd01d1d14965748b3e4account_status2account_type1creationdate2008-10-23mail_code39confirmedbb022e5a2419271daa2764f9cad5500crecoveryenabledreferrertimezonepreferred_currencycomission_plan1basemoney0privileges5paywaypersonal_info37last_update2008-10-23 00:00:00nameslastnamessexaddressphonemobilezipcitystatecountryidbusinessnameprofessionbirthdateaccount37usernamecjimenezhkemailyoyo@cjimenezhk.com

I'm not sure what you mean by "put the final HTML", but you should definitely move the

output = output + "</table>";

outside of your outer each loop.

Move it just before $('#user_results').html( output );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM