Web Design Forum: xmlhttprequest - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

xmlhttprequest

#1 User is offline   gadgetgirl 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 152
  • Joined: 26-February 10
  • Reputation: 6

Posted 24 January 2012 - 10:47 AM

I'm attempting to display a live weather feed in my web page. I have no experience with xmlhttprequest and limited javascript experience. How do I get the data from the xmlhttprequest to the php script? Here's my php which works on a static file (weather.php).
<?php
include 'weather.php';
$data= new SimpleXMLElement($xmlstr);
echo '<table id="forecast"><tr>';
	foreach ($data->weather as $weather) {
	$date = (string) $weather->date;
	$iconUrl = (string) $weather->weatherIconUrl;
	$maxF = (int) $weather->tempMaxF;
	$minF = (int) $weather->tempMinF;
	$desc = (string) $weather->weatherDesc;

	echo '<td><ul id="daily"><li class="desc">'. date('D', strtotime($date)) . '</li>
	<li><img src="' . $iconUrl . '" alt="weather icon" height="30" width="30"</li>
	<li class="temp">' . $maxF . '&deg/' . $minF . '&deg</li>
	</ul></td>';
	}
echo '</tr></table>';
echo '</body></html>';

?>


I know I need to do an xmlhttprequest similar to the code below to somehow send the data to the php script, but I'm not sure how to access the data from the php script. Please help.
request.onreadystatechange = function() {
	if request.readyState == 4 && request.status == 200{
		return true;
	}
}

if (window.XMLHttpRequest)  
	request=new XMLHttpRequest();  
	else request=new ActiveXObject("Microsoft.XMLHTTP");  // code for IE 6 or before.
	request.onreadystatechange;
	request.open("GET","forecast.php",true);  
	request.send();           // Send "Get" request to specified PHP script.
}

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users