开发者

How to manipulate the ajax response text

I've an ajax code like this:

var req = new XMLHttpRequest();

req.open('GET开发者_运维百科', 'http://www.example.org/', false); req.send(null);

if(req.status == 200)

var response = http_attendance.responseText; document.getElementById('divAttendance').innerHTML = response;

When I get result on the page, FF browser shows the DOM elements on 'divAttendance'. If I want to put put some jquery effect on the result, I can't be able to do it.

DOM elements is clearly viewed using firebug. But, when I generate the source code of that page then there is no repsonse text on 'divAttendance'. It is blank like thisL:

<html>
....
..
<div id="divAttendance"></div>
..
..
</html>

How to manipulate or put some effect on that result ???


Well, if you are using jQuery then you should be using jquery ajax anyways http://api.jquery.com/jQuery.ajax/

Regardless, if you are populating your div with AJAX response then it will not show up using "View Source" rather you will have to use a tool like firebug.

Your div initially should look like following

<div id="divAttendance" style="display:none"></div>

and your javascript should have the following

.....
document.getElementById('divAttendance').innerHTML = response;
$("#divAttendance").show("slow");

For such operations jQuery load is easy and usefull function, have a look at http://api.jquery.com/load/

Your specific example can be rewritten as

<html>
....
IMPORT JQUERY.JS
<script language="javascript">
$('#divAttendance').load('http://www.example.org/', function() {
 $("#divAttendance").show("slow");
});     
</script>
..
<div id="divAttendance" style="display:none"></div>
..
..
</html>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜