<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule">

<channel>
	<title>Werner Creixell &#187; Ajax</title>
	<atom:link href="http://profesores.elo.utfsm.cl/~wcreixell/index.html/?feed=rss2&#038;tag=ajax" rel="self" type="application/rss+xml" />
	<link>http://profesores.elo.utfsm.cl/~wcreixell</link>
	<description>Personal web page</description>
	<lastBuildDate>Fri, 20 Mar 2026 13:06:49 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.6.1</generator>
<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.0/cl/</creativeCommons:license>		<item>
		<title>Twitter Searchs</title>
		<link>http://profesores.elo.utfsm.cl/~wcreixell/?p=141</link>
		<comments>http://profesores.elo.utfsm.cl/~wcreixell/?p=141#comments</comments>
		<pubDate>Wed, 16 Jun 2010 20:09:50 +0000</pubDate>
		<dc:creator>Werner Creixell</dc:creator>
				<category><![CDATA[SeminarioII]]></category>
		<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[cross-domain]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[jacascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://profesores.elo.utfsm.cl/~wcreixell/?p=141</guid>
		<description><![CDATA[In Seminario II the students were challenged to make a web page that displays a Twitter search. The &#8220;#chi&#8221; or &#8220;#worldcup&#8221; hash-tag search is performed and the results dynamically displayed. Dominique Naser solution, using jQuery, can be found here (gracias Dominique). First a simple form to input the search. &#60;html> &#60;head> &#60;meta http-equiv="Content-type" content="text/html; charset=utf-8"> [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>In Seminario II the students were challenged to make a web page that displays a Twitter search. The &#8220;#chi&#8221; or &#8220;#worldcup&#8221; hash-tag search is performed and the results dynamically displayed.</p>
<p>Dominique Naser solution, using <a href="http://jquery.com/">jQuery</a>, can be found <a href="http://profesores.elo.utfsm.cl/~wcreixell/domnique/index.php">here</a> (gracias Dominique).</p>
<p>First a simple form to input the search.</p>
<pre name="code" class="html">
&lt;html>
  &lt;head>
    &lt;meta http-equiv="Content-type" content="text/html; charset=utf-8">
    &lt;title>Buscador de Hashtags&lt;/title>
  &lt;/head>
  &lt;body>
        &lt;h2>Buscador&lt;/h2>
    &lt;form action="busca.php" method="post">
                &lt;input name="busqueda" type="text" size="50" style="text-align:left" />
                &lt;input name="" type="submit" size="10" value="Busca!" />&lt;br>
        &lt;/form>
  &lt;/body>
&lt;/html>
</pre>
<p>The Html file where the search and the results display is performed.</p>
<pre name="code" class="html">
&lt;!DOCTYPE HTML>

&lt;html>

  &lt;head>

    &lt;meta http-equiv="Content-type" content="text/html; charset=utf-8">

    &lt;title>Buscador de Hashtags&lt;/title>

	        &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">&lt;/script>

        &lt;script type="text/javascript" src="http://github.com/malsup/corner/raw/master/jquery.corner.js?v2.09">&lt;/script>



	&lt;script>

	const MAX_RESULTS= 20;

function twitter_search() {

	var url = 'http://search.twitter.com/search.json?callback=?';

	// Iterating over the different search columns

	$('.twitter_search').each(function() {

		var container = $(this);

		// Search terms are specified in the 'title' attribute

		var search = container.attr('title');

		if (search) {

			var since_id = 0;

			if (container.children().length) {

				// Retrieve results since this id

				since_id = container.children(':first').attr('id').replace('#', '%23');

			}

			// Request the results

			$.getJSON(url, {'q': search, 'since_id': since_id}, function(data) {

				// Processing those results, if any

				if (data.results.length) {

					for (i in data.results.reverse()) {

						var r = data.results[i];

						// Creating the result container

						var div = $('&lt;div id="#' + r.id + '">&lt;/div>');

						// Don't show this element now

						div.hide();

						// Adding some styles through .twitter_result

						div.addClass('twitter_result');

						// Adding user's image

						div.append('&lt;img src="' + r.profile_image_url + '" alt="' + r.from_user + '" />');

						// Adding username

						div.append('&lt;a href="http://twitter.com/' + r.from_user + '">' + r.from_user + '&lt;/a>');

						// Adding tweet

						div.append('&lt;span>' + r.text + '&lt;/span>');

						// Adding corners

						div.corner();

						// Adding this result to the main container

						container.prepend(div);

						// Effect

						div.slideDown('slow');

					}

				}

				// Removing old tweets

				if (container.children().length > MAX_RESULTS) {

					// Negative index

					to_remove = MAX_RESULTS - container.children().length

					container.children().slice(to_remove).each(function() {

						$(this).slideUp();

					});

				}

			});

		}

	});

};

 

$(document).ready(function() {

	// Initial search 

	twitter_search();

	// Refresh the results every 5 seconds

	setInterval("twitter_search();", 5000);

});

	&lt;/script>

  &lt;/head>

  &lt;body>

	&lt;h2>Resultado&lt;/h2>

		

		&lt;div class="twitter_search" title="&lt;?php echo $_POST["busqueda"]; ?>">&lt;/div>	



  &lt;/body>

&lt;/html>

</pre>
<p>Diego Acevedo, used a <a href="http://jquery.com/">jQuery</a> plugin <a href="http://juitter.com">Juitter</a> (gracias Diego). You can found his solution <a href="http://profesores.elo.utfsm.cl/~wcreixell/diego/index.html">here</a></p>
<p>Both solutions  by pass the cross-domain restriction imposed by the browser.</p>
]]></content:encoded>
			<wfw:commentRss>http://profesores.elo.utfsm.cl/~wcreixell/?feed=rss2&#038;p=141</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Yahoo Weather in Google Maps</title>
		<link>http://profesores.elo.utfsm.cl/~wcreixell/?p=70</link>
		<comments>http://profesores.elo.utfsm.cl/~wcreixell/?p=70#comments</comments>
		<pubDate>Wed, 12 May 2010 12:58:56 +0000</pubDate>
		<dc:creator>Werner Creixell</dc:creator>
				<category><![CDATA[SeminarioII]]></category>
		<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[RSS]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[Yahoo! Weather]]></category>

		<guid isPermaLink="false">http://profesores.elo.utfsm.cl/~wcreixell/?p=70</guid>
		<description><![CDATA[This is a toy example that I used to challenge my students at seminario II. The idea is to display the Yahoo! Weather information in a google map, as showed in this page (click in the marker and the weather info for Valparaíso will appear). We first grab the information, by a php script, from [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>This is a toy example that I used to challenge my students at <a href="http://www.ramos.utfsm.cl/index.php?id=1172" target="_blank">seminario II</a>. The idea is to display the <a href="http://weather.yahoo.com/" target="_blank">Yahoo! Weather </a>information in a <a href="http://maps.google.com/" target="_blank">google map</a>, as showed in <a href="http://www.profesores.elo.utfsm.cl/~wcreixell/ejemplos/map3.html" target="_blank">this page</a> (click in the marker and the weather info for Valparaíso will appear).</p>
<p>We first grab the information, by a php script, from the Yahoo! Weather RSS feed. The feed is available from  the URL http://weather.yahooapis.com/forecastrss?w=349861&amp;u=c,  where w is the corresponding code for Valparaíso, and u is the temperature unit in Celsius. This php scrip can communicate with the client (the html page with the map) by  JSON or XML. The XML version is contributed by Jorge Flores a student in Seminario II (¡¡Gracias Jorge!!).<br />
The XML from the feed looks like</p>
<pre name="code" class="XML:nogutter">
&lt;?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
&lt;rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
&lt;channel>

&lt;title>Yahoo! Weather - Valparaiso, CI&lt;/title>
&lt;link>http://us.rd.yahoo.com/dailynews/rss/weather/Valparaiso__CI/*http://weather.yahoo.com/forecast/CIXX0026_c.html&lt;/link>
&lt;description>Yahoo! Weather for Valparaiso, CI&lt;/description>
&lt;language>en-us&lt;/language>
&lt;lastBuildDate>Tue, 11 May 2010 6:00 pm CLT&lt;/lastBuildDate>
&lt;ttl>60&lt;/ttl>
&lt;yweather:location city="Valparaiso" region=""   country="CI"/>

&lt;yweather:units temperature="C" distance="km" pressure="mb" speed="km/h"/>
&lt;yweather:wind chill="11"   direction="190"   speed="9.66" />
&lt;yweather:atmosphere humidity="88"  visibility="4.01"  pressure="982.05"  rising="0" />
&lt;yweather:astronomy sunrise="7:26 am"   sunset="5:58 pm"/>
&lt;image>
&lt;title>Yahoo! Weather&lt;/title>
&lt;width>142&lt;/width>
&lt;height>18&lt;/height>
&lt;link>http://weather.yahoo.com&lt;/link>
&lt;url>http://l.yimg.com/a/i/us/nws/th/main_142b.gif&lt;/url>
&lt;/image>
&lt;item>

&lt;title>Conditions for Valparaiso, CI at 6:00 pm CLT&lt;/title>
&lt;geo:lat>-32.78&lt;/geo:lat>
&lt;geo:long>-71.53&lt;/geo:long>
&lt;link>http://us.rd.yahoo.com/dailynews/rss/weather/Valparaiso__CI/*http://weather.yahoo.com/forecast/CIXX0026_c.html&lt;/link>
&lt;pubDate>Tue, 11 May 2010 6:00 pm CLT&lt;/pubDate>
&lt;yweather:condition  text="Fog"  code="20"  temp="11"  date="Tue, 11 May 2010 6:00 pm CLT" />
&lt;description>&lt;![CDATA[
&lt;img src="http://l.yimg.com/a/i/us/we/52/20.gif"/>&lt;br />
&lt;b>Current Conditions:&lt;/b>&lt;br />
Fog, 11 C&lt;BR />
&lt;BR />&lt;b>Forecast:&lt;/b>&lt;BR />
Tue - Cloudy. High: 20 Low: 9&lt;br />
Wed - Partly Cloudy. High: 20 Low: 9&lt;br />
&lt;br />
&lt;a href="http://us.rd.yahoo.com/dailynews/rss/weather/Valparaiso__CI/*http://weather.yahoo.com/forecast/CIXX0026_c.html">Full Forecast at Yahoo! Weather&lt;/a>&lt;BR/>&lt;BR/>
(provided by &lt;a href="http://www.weather.com" >The Weather Channel&lt;/a>)&lt;br/>
]]&gt;&lt;/description>
&lt;yweather:forecast day="Tue" date="11 May 2010" low="9" high="20" text="Cloudy" code="26" />
&lt;yweather:forecast day="Wed" date="12 May 2010" low="9" high="20" text="Partly Cloudy" code="30" />
&lt;guid isPermaLink="false">CIXX0026_2010_05_11_18_00_CLT&lt;/guid>
&lt;/item>

&lt;/channel>
&lt;/rss>&lt;!-- api4.weather.ac4.yahoo.com compressed/chunked Wed May 12 06:05:42 PDT 2010 -->
</pre>
<p>We can observe that there are two different name spaces, yweather and geo. We need just those names under yweather. In particular we use yweather:condition, this element holds the current weather information on its attributes. </p>
<h2>JSON version</h2>
<p>The php goes as follows</p>
<pre name="code" class="php">&lt;?php
//First send the corresponding headers
header("Content-type= application/json");
//get the XML data from the URL
$xml = simplexml_load_file("http://weather.yahooapis.com/forecastrss?w=349861&amp;u=c");
//obtaining the namespace for yweather
$yweather =$xml->channel->item->children("http://xml.weather.yahoo.com/ns/rss/1.0");

//traverse the SimpleXML object and store in a associative array
foreach( $yweather->condition->attributes() as $k=>$attr)
     $condition[$k] = $attr;

//JSON enconde and print
print(json_encode($condition));
?&gt;
</pre>
<p>On the html page we receive the information in the JSON format and passed to the openInfoWindowHtml() method of google maps.</p>
<pre name="code" class="html">
&lt;!DOCTYPE html "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
&lt;html xmlns="http://www.w3.org/1999/xhtml">
  &lt;head>
    &lt;meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    &lt;title>Google Maps JavaScript API Example&lt;/title>
    &lt;script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAADI36Gd6uqs4OgrvF2FK3TRS3WQwwXk35PFrPy_oZlvjggyWGmxSJfJA31Kd06D9lQVQJpKvCzFGD3g"
            type="text/javascript">&lt;/script>
    &lt;script type="text/javascript">

function initialize() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map_canvas"));
   //a marker placed in our university 
    var center = new GLatLng(-33.033276,-71.594682);
    map.setCenter(center, 15);

    var marker = new GMarker(center, {draggable: true});

   		
		//Adding Yahoo! Weather
		
		GEvent.addListener(marker, "click", 
		function(){
        // create the Google version of XMLHttpRequest object
			var request = GXmlHttp.create();
			request.open("GET", "weather2.php", true);
			
			request.onreadystatechange = function() {
				
				if(request.readyState == 4 &#038;&#038; request.status == 200){
					
					var xhtml = "&lt;b>Yahoo! Weather&lt;/b>";
					xhtml += "&lt;br />";
					
					var yw_json = request.responseText;
                      //dirty JSON evaluation
					var yw = eval('(' + yw_json + ')');
					
					xhtml = xhtml + "temperatura =" + yw.temp[0] +" ºC &lt;br />";
					xhtml += yw.date[0];
					marker.openInfoWindowHtml(xhtml);
				}
			}
			//send the request
			request.send(null);
		});
		
		
    map.addOverlay(marker);

  }
}​
   &lt;/script>
  &lt;/head>
  &lt;body onload="initialize()" onunload="GUnload()">
    &lt;div id="map_canvas" style="width: 800px; height: 500px">&lt;/div>
  &lt;/body>
&lt;/html>
</pre>
<h2>XML version</h2>
<p>The php goes as follows</p>
<pre name="code" class="php">
&lt;?php
//First the corresponding XML headers
header("Content-type: text/xml");
//Jorge sends the location by GET
$w = $_GET["w"];
$url =  "http://weather.yahooapis.com/forecastrss?w=" . $w . "&#038;u=c";
if($xml = file_get_contents($url)){

	$obj = simplexml_load_string($xml);
	$item = $obj->channel->item;
//formatting the XML output
	print("&lt;weather>");
	print("&lt;title>" . $item->title . "&lt;/title>");
//getting the namespace
	$child = $item->children("http://xml.weather.yahoo.com/ns/rss/1.0");
	$att = $child->condition->attributes();
	print("&lt;temp>" . $att->text . " " . $att->temp . "ºC&lt;/temp>");
	print("&lt;/weather>");
}
?>
</pre>
<p>Jorge&#8217;s html file goes like this</p>
<pre name="code" class="html">
&lt;html>
	&lt;head>
	&lt;script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAzsVe8ueaD3_5_TOp88LiKRTmhXfEnveThyX0qgmXnRV_0BrCwBTi62Ue7Uv5MEgulw1nxTmAQ2jihA" type="text/javascript">&lt;/script>
		&lt;script type="text/javascript">
			function load(){
				var map = new GMap2(document.getElementById("map"));

				var point = new GLatLng(-33.05,-71.6);
				var w = 349861;

				map.setCenter(point,13);

				var marker = new GMarker(point);
				map.addOverlay(marker);

				GEvent.addListener(marker,"click",function(){
						var request = GXmlHttp.create();
						request.open("GET","getWeather.php?w=" + w,true);
						request.onreadystatechange = function(){
							if(request.readyState == 4 &#038; request.status == 200){

								var weather = request.responseXML.getElementsByTagName("weather")[0];
								var title = weather.getElementsByTagName("title")[0].firstChild.nodeValue;
								var temp = weather.getElementsByTagName("temp")[0].firstChild.nodeValue;

								var xhtml = "&lt;b>" + title + ":&lt;/b> &lt;br />";

								xhtml += "&lt;div align=center>&lt;h2>" + temp + "&lt;/h2>&lt;/div>";

								map.openInfoWindowHtml(point,xhtml);
							}
						}
						request.send(null);
					}
					);
			}
		&lt;/script>
	&lt;/head>
	&lt;body onload="load();">
		&lt;div id="map" style="height:100%; width:100%"> &lt;/div>
	&lt;/body>

&lt;/html>
</pre>
<p>The main differences with the JSON version are in the request.onreadystatechange handler, where there is a little more code to traverse the XML data. You can check the result <a href="http://www.profesores.elo.utfsm.cl/~wcreixell/ejemplos/weathermap.html">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://profesores.elo.utfsm.cl/~wcreixell/?feed=rss2&#038;p=70</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
