Jump to content

Xmlhttprequest


toreachdeepak

Recommended Posts

Hi,I am using example of using AJAX from XMLHttpRequest.The code given in the W3Schools Ajax tutorial is working with gethint.php page sending a simple string as response.But the url in my case is the HTML page returned back.How do I send a complete HTML page as response (xmlhttp.responseText) as given below ?ThanksDeepak==============================================================================<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><?php use_helper('Form'); ?><?php use_helper('DateForm') ?><?php use_helper('Javascript') ?><?php use_javascript('testfunc') ?><?php use_javascript('Date') ?> <script type="text/javascript"> YAHOO.namespace("example.calendar"); YAHOO.example.calendar.init = function() { function handleSelect(type,args,obj) { var dates = args[0]; var date = dates[0]; var year = date[0], month = date[1], day = date[2]; var caldate = month + "/" + day + "/" + year; calday= new Date(caldate); var days= calday.getDay(); var weekdays=new Array(7); weekdays[0]="Sunday"; weekdays[1]="Monday"; weekdays[2]="Tuesday"; weekdays[3]="Wednesday"; weekdays[4]="Thursday"; weekdays[5]="Friday"; weekdays[6]="Saturday"; var calmonths=new Array(7); calmonths[0]="January"; calmonths[1]="February"; calmonths[2]="March"; calmonths[3]="April"; calmonths[4]="May"; calmonths[5]="June"; calmonths[6]="July"; calmonths[7]="August"; calmonths[8]="September"; calmonths[9]="October"; calmonths[10]="November"; calmonths[11]="December"; var months= calday.getMonth(); var txtDate1 = document.getElementById("date1"); txtDate1.innerHTML = weekdays[days] + ", " + calmonths[months] + " " + day + ", " + year; if(month <10) { var month1="0"+month; } else { var month1= month; } if(day <10) { var day1="0"+day; } else { var day1= day; } var selectdate= year + "-" + month1 + "-" + day1; window.location.replace("/crb/web/tool_staging.php/home/showfullbooking?id="+selectdate); } function updateCal() { var txtDate1 = document.getElementById("date1"); if (txtDate1.value != "") { YAHOO.example.calendar.cal1.select(txtDate1.value); var selectedDates = YAHOO.example.calendar.cal1.getSelectedDates(); if (selectedDates.length > 0) { var firstDate = selectedDates[0]; YAHOO.example.calendar.cal1.cfg.setProperty("pagedate", (firstDate.getMonth()+1) + "/" + firstDate.getFullYear()); YAHOO.example.calendar.cal1.render(); } else { alert("Cannot select a date before 1/1/2006 or after 12/31/2010"); } } } // For this example page, stop the Form from being submitted, and update the cal instead function handleSubmit(e) { updateCal(); YAHOO.util.Event.preventDefault(e); } YAHOO.example.calendar.cal1 = new YAHOO.widget.Calendar("cal1","cal1Container", { mindate:"1/1/2009", maxdate:"12/31/2015" }); YAHOO.example.calendar.cal1.selectEvent.subscribe(handleSelect, YAHOO.example.calendar.cal1, true); YAHOO.example.calendar.cal1.render(); YAHOO.util.Event.addListener("update", "click", updateCal); YAHOO.util.Event.addListener("dates", "submit", handleSubmit); } YAHOO.util.Event.onDOMReady(YAHOO.example.calendar.init); </script><div id="common_area"> <div id="calset"> </div> <div id="cal1Container" style="left:35px;top:280px;position:absolute;"></div><div id="bookingentry"> <div id="mainarea"> <div id="mainbar"> <h1>Room Booking Status </h1> <div id ="dateset"> <h2 name="date1" id="date1"></h2> <h2><?php /*var $caldate = $currentmonth + "/" + $currentday + "/" + $currentyear; $calday= new Date($caldate); var days= calday.getDay();*/ $weekdays[0]="Sunday"; $weekdays[1]="Monday"; $weekdays[2]="Tuesday"; $weekdays[3]="Wednesday"; $weekdays[4]="Thursday"; $weekdays[5]="Friday"; $weekdays[6]="Saturday"; $calmonths[0]="January"; $calmonths[1]="February"; $calmonths[2]="March"; $calmonths[3]="April"; $calmonths[4]="May"; $calmonths[5]="June"; $calmonths[6]="July"; $calmonths[7]="August"; $calmonths[8]="September"; $calmonths[9]="October"; $calmonths[10]="November"; $calmonths[11]="December"; $currentyear=substr($currentdate,0,4); $currentmonth=substr($currentdate,5,2); $currentday=substr($currentdate,8,2); $num = (int)$currentmonth; $dateofweek =", " . $calmonths[$num-1] . " " . $currentday . ", " . $currentyear; echo date("l",$tdate); echo $dateofweek; /*echo $currentyear; echo $currentmonth; echo $currentday;*/ ?> </h2> </div> <!-- dateset --> </div> <!-- mainbar --> <div id="area"><div id="button_setting" style="left:280px;top:245px;position:absolute"><?php $temp = 1; ?><?php echo link_to_remote(image_tag('/crb/web/images/BabeLb3.gif',array('border' => "0",'alt' => 'Previous Day', 'title' => 'Previous Day')), array('update' => 'bookingentry','url' => 'home/displaybooking?ss='.$temp,'script' => true,)); ?></div><?php echo form_remote_tag(array('update' => 'bookingentry','url' => 'home/displaybooking','script' => true)); ?><div id="button_setting" style="left:550px;top:250px;position:absolute"><?php echo input_date_tag('selectdate', $currentdate, 'rich=true') ?></div><div id="button_setting" style="left:686px;top:245px;position:absolute"><input type="image" src="/crb/web/images/BabeLf3.gif" title='Go to desired date'/></div><input type="hidden" id="ss" name="ss" value="3"/></form><div id="button_setting" style="left:950px;top:245px;position:absolute"><?php $temp = 2; ?><?php echo link_to_remote(image_tag('/crb/web/images/BabeLc3.gif',array('border' => "0",'alt' => 'Next Day', 'title' => 'Next Day')), array('update' => 'bookingentry','url' => 'home/displaybooking?ss='.$temp,'script' => true,)); ?></div> <table id="dataset" border="1" cellspacing="1" cellpadding="5" height=70% > <tr bgcolor="#F8F8F8"> <td align="center"> <font size=4 color=#253183> Time </font> </td> <?php foreach($room_tuple as $rt): ?> <?php if($rt->getStatus() == 1): ?> <?php if($rt->getNoOfVideoequip() == 1): ?> <td align="center"> <font size=4 color=#253183 > <?php echo $rt->getName();?> </font>    <img src="/crb/web/images/video.jpg" width="50" height="28" title="Videoconferencing Equipment"/> </td> <?php else: ?> <td align="center"> <font size=4 color=#253183 > <?php echo $rt->getName();?> </font> </td> <?php endif; ?> <?php endif; ?> <?php endforeach; ?> </tr> <tr> <?php foreach($hours_info as $hi):?> <tr> <?php if($hourcount != $hi->getId()):?> <td width="5%" align="center"><font size="4" color=#253183><?php echo $hi->getHourName();?></font></td> <?php endif; ?> <?php foreach($room_tuple as $rt): ?> <?php if($rt->getStatus() == 1): ?> <?php if(($room_hour_booking[$hourcount*($rt->getId()-1)+$hi->getId()] == 1) && ($room_hour_booking_name[$hourcount*($rt->getId()-1)+$hi->getId()] != "")):?> <?php if($room_employee_id[$hourcount*($rt->getId()-1)+$hi->getId()] == $emp):?><?php if(($videocon_req[$hourcount*($rt->getId()-1)+$hi->getId()] == 1) && ($projector_req[$hourcount*($rt->getId()-1)+$hi->getId()] == 1)):?> <td class="type1" bgcolor=#A0CFEC width="10%" title="Internal Meeting"><font color=#253183 size="2"><?php echo $room_hour_booking_name[$hourcount*($rt->getId()-1)+$hi->getId()]; ?></font> <img src="/crb/web/images/videocon.jpg" width="26" height="15" title="Videocon Required"/>  <img src="/crb/web/images/sony.gif" width="14" height="15" title="Projector Required"/></td> <?php elseif(($videocon_req[$hourcount*($rt->getId()-1)+$hi->getId()] == 1) && ($projector_req[$hourcount*($rt->getId()-1)+$hi->getId()] == 2)):?><td class="type1" bgcolor=#A0CFEC width="10%" title="Internal Meeting"><font color=#253183 size="2"><?php echo $room_hour_booking_name[$hourcount*($rt->getId()-1)+$hi->getId()]; ?></font>   <img src="/crb/web/images/videocon.jpg" width="26" height="15" title="Videocon Required"/></td> <?php elseif(($videocon_req[$hourcount*($rt->getId()-1)+$hi->getId()] == 0) && ($projector_req[$hourcount*($rt->getId()-1)+$hi->getId()] == 1)):?><td class="type1" bgcolor=#A0CFEC width="10%" title="Internal Meeting"><font color=#253183 size="2"><?php echo $room_hour_booking_name[$hourcount*($rt->getId()-1)+$hi->getId()]; ?></font>   <img src="/crb/web/images/sony.gif" width="14" height="15" title="Projector Required"/></td> <?php else: ?> <td class="type1" bgcolor=#A0CFEC width="10%" title="Internal Meeting"><font color=#253183 size="2"><?php echo $room_hour_booking_name[$hourcount*($rt->getId()-1)+$hi->getId()]; ?></font></td> <?php endif;?><?php else :?><?php $parameter_passed=$room_employee_id[$hourcount*($rt->getId()-1)+$hi->getId()].','.$todaydate.','.$rt->getId().','.$hi->getId();?> <?php if(($videocon_req[$hourcount*($rt->getId()-1)+$hi->getId()] == 1) && ($projector_req[$hourcount*($rt->getId()-1)+$hi->getId()] == 1)):?> <td bgcolor=#A0CFEC width="10%" title="Send Cancellation Request"><font size="2"><?php echo link_to_remote($room_hour_booking_name[$hourcount*($rt->getId()-1)+$hi->getId()], array('update' => 'feedback','url' => 'home/homemail?id='.$parameter_passed,)) ?></font>  <img src="/crb/web/images/videocon.jpg" width="26" height="15" title="Videocon required"/> <img src="/crb/web/images/sony.gif" width="14" height="15" title="Projector required"/></td> <?php elseif(($videocon_req[$hourcount*($rt->getId()-1)+$hi->getId()] == 1) && ($projector_req[$hourcount*($rt->getId()-1)+$hi->getId()] == 2)): ?> <td bgcolor=#A0CFEC width="10%" title="Send Cancellation Request"><font size="2"><?php echo link_to_remote($room_hour_booking_name[$hourcount*($rt->getId()-1)+$hi->getId()], array('update' => 'feedback','url' => 'home/homemail?id='.$parameter_passed,)) ?></font>  <img src="/crb/web/images/videocon.jpg" width="26" height="15" title="Videocon required"/></td> <?php elseif(($videocon_req[$hourcount*($rt->getId()-1)+$hi->getId()] == 0) && ($projector_req[$hourcount*($rt->getId()-1)+$hi->getId()] == 1)): ?> <td bgcolor=#A0CFEC width="10%" title="Send Cancellation Request"><font size="2"><?php echo link_to_remote($room_hour_booking_name[$hourcount*($rt->getId()-1)+$hi->getId()], array('update' => 'feedback','url' => 'home/homemail?id='.$parameter_passed,)) ?></font>  <img src="/crb/web/images/sony.gif" width="14" height="15" title="Projector required"/></td> <?php else: ?> <td bgcolor=#A0CFEC width="10%" title="Send Cancellation Request"><font size="2"><?php echo link_to_remote($room_hour_booking_name[$hourcount*($rt->getId()-1)+$hi->getId()], array('update' => 'feedback','url' => 'home/homemail?id='.$parameter_passed,)) ?></font></td> <?php endif;?> <?php endif;?> <?php elseif(($room_hour_booking[$hourcount*($rt->getId()-1)+$hi->getId()] == 1) && ($room_hour_booking_name[$hourcount*($rt->getId()-1)+$hi->getId()] == 0)): ?> <?php if($room_employee_id[$hourcount*($rt->getId()-1)+$hi->getId()] == $emp):?> <td class="type1" bgcolor=#A0CFEC width="10%" title="Internal Meeting"></td> <?php else: ?> <td bgcolor=#A0CFEC width="10%" title="Internal Meeting"></td> <?php endif; ?> <?php elseif(($room_hour_booking[$hourcount*($rt->getId()-1)+$hi->getId()] == 2) && ($room_hour_booking_name[$hourcount*($rt->getId()-1)+$hi->getId()] != "")):?> <?php if($room_employee_id[$hourcount*($rt->getId()-1)+$hi->getId()] == $emp):?><?php if(($videocon_req[$hourcount*($rt->getId()-1)+$hi->getId()] == 1) && ($projector_req[$hourcount*($rt->getId()-1)+$hi->getId()] == 1)):?> <td class="type1" bgcolor=#B4CFEC width="10%" title="Client Meeting"><font color=#253183 size="2"><?php echo $room_hour_booking_name[$hourcount*($rt->getId()-1)+$hi->getId()]; ?></font> <img src="/crb/web/images/videocon.jpg" width="26" height="15" title="Videocon Required"/>  <img src="/crb/web/images/sony.gif" width="14" height="15" title="Projector Required"/></td> <?php elseif(($videocon_req[$hourcount*($rt->getId()-1)+$hi->getId()] == 1) && ($projector_req[$hourcount*($rt->getId()-1)+$hi->getId()] == 2)):?><td class="type1" bgcolor=#B4CFEC width="10%" title="Client Meeting"><font color=#253183 size="2"><?php echo $room_hour_booking_name[$hourcount*($rt->getId()-1)+$hi->getId()]; ?></font>   <img src="/crb/web/images/videocon.jpg" width="26" height="15" title="Videocon Required"/></td> <?php elseif(($videocon_req[$hourcount*($rt->getId()-1)+$hi->getId()] == 0) && ($projector_req[$hourcount*($rt->getId()-1)+$hi->getId()] == 1)):?><td class="type1" bgcolor=#B4CFEC width="10%" title="Client Meeting"><font color=#253183 size="2"><?php echo $room_hour_booking_name[$hourcount*($rt->getId()-1)+$hi->getId()]; ?></font>   <img src="/crb/web/images/sony.gif" width="14" height="15" title="Projector Required"/></td> <?php else: ?> <td class="type1" bgcolor=#B4CFEC width="10%" title="Client Meeting"><font color=#253183 size="2"><?php echo $room_hour_booking_name[$hourcount*($rt->getId()-1)+$hi->getId()]; ?></font></td> <?php endif;?> <?php else: ?><?php $parameter_passed=$room_employee_id[$hourcount*($rt->getId()-1)+$hi->getId()].','.$todaydate.','.$rt->getId().','.$hi->getId();?> <?php if(($videocon_req[$hourcount*($rt->getId()-1)+$hi->getId()] == 1) && ($projector_req[$hourcount*($rt->getId()-1)+$hi->getId()] == 1)):?> <td bgcolor=#A0CFEC width="10%" title="Send Cancellation Request"><font size="2"><?php echo link_to_remote($room_hour_booking_name[$hourcount*($rt->getId()-1)+$hi->getId()], array('update' => 'feedback','url' => 'home/homemail?id='.$parameter_passed,)) ?></font>  <img src="/crb/web/images/videocon.jpg" width="26" height="15" title="Videocon required"/> <img src="/crb/web/images/sony.gif" width="14" height="15" title="Projector required"/></td> <?php elseif(($videocon_req[$hourcount*($rt->getId()-1)+$hi->getId()] == 1) && ($projector_req[$hourcount*($rt->getId()-1)+$hi->getId()] == 2)): ?> <td bgcolor=#A0CFEC width="10%" title="Send Cancellation Request"><font size="2"><?php echo link_to_remote($room_hour_booking_name[$hourcount*($rt->getId()-1)+$hi->getId()], array('update' => 'feedback','url' => 'home/homemail?id='.$parameter_passed,)) ?></font>  <img src="/crb/web/images/videocon.jpg" width="26" height="15" title="Videocon required"/></td> <?php elseif(($videocon_req[$hourcount*($rt->getId()-1)+$hi->getId()] == 0) && ($projector_req[$hourcount*($rt->getId()-1)+$hi->getId()] == 1)): ?> <td bgcolor=#A0CFEC width="10%" title="Send Cancellation Request"><font size="2"><?php echo link_to_remote($room_hour_booking_name[$hourcount*($rt->getId()-1)+$hi->getId()], array('update' => 'feedback','url' => 'home/homemail?id='.$parameter_passed,)) ?></font>  <img src="/crb/web/images/sony.gif" width="14" height="15" title="Projector required"/></td> <?php else: ?> <td bgcolor=#A0CFEC width="10%" title="Send Cancellation Request"><font size="2"><?php echo link_to_remote($room_hour_booking_name[$hourcount*($rt->getId()-1)+$hi->getId()], array('update' => 'feedback','url' => 'home/homemail?id='.$parameter_passed,)) ?></font></td> <?php endif;?> <?php endif; ?> <?php elseif(($room_hour_booking[$hourcount*($rt->getId()-1)+$hi->getId()] == 2) && ($room_hour_booking_name[$hourcount*($rt->getId()-1)+$hi->getId()] == 0)): ?> <?php if($room_employee_id[$hourcount*($rt->getId()-1)+$hi->getId()] == $emp):?> <td class="type1" bgcolor=#B4CFEC width="10%" title="Client Meeting"></td> <?php else: ?> <td bgcolor=#B4CFEC width="10%" title="Client Meeting"></td> <?php endif; ?> <?php else: ?> <?php if($hourcount != $hi->getId()): ?> <?php $value = $rt->getId().",".$tdate.",".$hi->getId();?> <?php if($band == 1): ?> <td title="Click to select" id="mousetype" bgcolor=#EEEEEE width="10%"><?php echo link_to_remote(image_tag('/crb/web/images/tdimage.jpg'), array('update' => 'common_area','url' => 'book/booknew?id='.$value,'script' => true,)); ?></td> <?php elseif(($rt->getSecurity() == 1) && ($band == 0)): ?> <td title="Click to select" id="mousetype" bgcolor=#EEEEEE width="10%"><?php echo link_to_remote(image_tag('/crb/web/images/tdimage.jpg'), array('update' => 'common_area','url' => 'book/booknew?id='.$value,'script' => true,)); ?></td> <?php else: ?> <td title="Click to select" bgcolor=#EEEEEE width="10%"><img src="/crb/web/images/tdimage.jpg"></td> <?php endif; ?> <?php endif; ?> <?php endif; ?> <?php endif; ?> <?php endforeach; ?> </tr> <?php endforeach; ?> </tr> </table></div> </div> <!-- area --> </div> <!-- mainarea --></div> <!-- common_area --></body></html>

Link to comment
Share on other sites

The only way to get a whole HTML document to be interpretted upon being received is to use the document.write() statement:

document.write(xmlHttp.responseText)

The drawback of this is that anything you had in your page previously is gone now, so any other Javascript you intended to run from the original page won't work anymore.But why do you want to interpret an entire web page received through AJAX? It is just as worth it to just open the other page.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...