Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to Load data into a Div using Javascript when the page loads. I'm using jQuery mobile (i'm new to this). the page is called using normal href, which i assume gets hijacked into Ajax by JQM.

but my Javascript seems to behave somewhat strangely, all the script runs ( i checked that using alerts) but the append function doesnt seem to have any effect on the Page. I've tried all sorts of fuctions :- pagecreate, pagebeforeshow, document.ready.

Please help ASAP.

Heres my code (only relevant parts) :

HTML
<body>

<div data-role="page" id="page">

    <div data-role="removed" style="padding:0" data-theme="k">

    <ul class="rig columns-3" style="margin:0;padding-removed0;padding-removed8px;padding-removed20vw" id="DrinkGridView">

    <!-- <li>
    <img src="images/logo.png" />
    <h3>Image Title</h3>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit...</p>
    </li> -->

 </ul>
        </div><!-- /content -->

<script type="text/javascript">

//$( document ).delegate("#page", "pageinit", function() {

var global_id;
var global_data;

var fields = [];

$.ajax({                    
    type: "POST",
    url: "http://192.168.1.120/yiibootstrap_old/index.php/userregistration/makedrink",
    cache: false,
    success: function(data)
    {

    var obj = $.parseJSON(data);
    $.each(obj, function() 
    {                           
         fields.push({id:this['id'],name:this['name'],image:this['image'],Description:this['description']});            
    });

    var count=fields.length;                 

    count1=parseInt(count);

    for(var r = 0; r < count1; r++)
        {

        $('#DrinkGridView').append('<a id="inline" href=#data><li id="'+fields[r]['id']+'"> <img src="http://192.168.1.120/yiibootstrap_old/uploads/'+fields[r]['image']+'"/> <h3>'+fields[r]['name']+'</h3> <p id="sss">'+fields[r]['Description']+'</p> </li></a>').children().last().trigger("create");

    // THIS APPEND IS NOT SHOWING RESULT !!
        }
        });
 //});
 </script>  
 </div><!-- /page -->
</body>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900