How to get load html with Ajax and jQuery -
i'm using jquerymobile. have page gets latest posts click on refresh button.
i can't html viewposts.php show in #test div.
$("#refresh").click(function(){ $.ajax({ cache: false, url: "mobile/viewposts.php", success: function (html) { $("#test").append(html); $("#test").fadeout(1000); alert(html); } });
i have tried datatype: 'html', , type: 'post', , get.
tried $("#test").html(html);
the fadeout works. alert blank.
the view posts page gets latest posts db. i'm echoing random html in viewposts.php.
i'm able ajax call , html if don't use jquery. problem way html thats returned doesn't use jquerymobile stylesheet looks plain text.
i'm new this.
please help.
<div data-role="page" id="readblogpage"> <div data-role="header"> <h1>read blog</h1> </div> <div data-role="content"> <!--<button onclick="ajaxfunction()" data-theme="b" data-role="button" data-iconpos="left" data-icon="refresh" >refresh</button>--> <fieldset class="ui-grid-a"> <div class="ui-block-a"><a href="#createnewpostpage" id="cancel" data-role="button" data-rel="dialog">new post</a></div> <div class="ui-block-b"><button id="refresh" data-theme="b" data-role="button" data-iconpos="left" data-icon="refresh" type="submit">refresh</button></div> </fieldset> <!--<button onclick="ajaxfunction()" data-theme="b" data-role="button" data-iconpos="left" data-icon="refresh" id="refresh" type="button">refresh</button>--> <ul data-role="listview" data-theme="d" data-inset="true" id="ajaxout"> </ul> <div id="test" >asdfsadfsd</div> </div> </div>
viewposts.php echoes bunch of lines this
echo "<li><h3 style=\"margin:0px;\">" . $ row['post_title'] . "</h2>" . $row['post_content'] . "<p class='ui-li-aside'>lat: ". $row['lat'] ." lon: ". $row['lon'] ." " .$row['post_date'] . "<strong></p></li>";
this response header in firebug
response headers date sun, 03 jul 2011 17:38:20 gmt server apache/2.2.3 (red hat) x-powered-by php/5.1.6 cache-control max-age=0 expires sun, 03 jul 2011 17:38:20 gmt content-length 0 connection close content-type text/html; charset=utf-8 x-pad avoid browser bug
basically can see (please correct me if wrong) trying put html form viewposts.php file $("#test"),
your trying this:
functionn(html){ $("#test").append(html); }
jquery ajax returns: data, try:
function(data){ $("#test".append(data); }
Comments
Post a Comment