cvs: presentations /slides/intro yajax.xml yajax_combined.php yajax_geocode.php
| From: | Rasmus Lerdorf | Date: | Mon, 17 Apr 2006 08:14:08 +0000 |
| Subject: | cvs: presentations /slides/intro yajax.xml yajax_combined.php yajax_geocode.php | ||
| Groups: | php.pres | ||
| Request: | Send a blank email to pres+get-1279@lists.php.net to get a copy of this message | ||
rasmus Mon Apr 17 08:14:08 2006 UTC
Added files:
/presentations/slides/intro yajax_combined.php yajax_geocode.php
Modified files:
/presentations/slides/intro yajax.xml
Log:
A few more asynchronous request examples
http://cvs.php.net/viewcvs.cgi/presentations/slides/intro/yajax.xml?r1=1.1&r2=1.2&diff_format=u
Index: presentations/slides/intro/yajax.xml
diff -u presentations/slides/intro/yajax.xml:1.1 presentations/slides/intro/yajax.xml:1.2
--- presentations/slides/intro/yajax.xml:1.1 Sat Apr 1 12:47:43 2006
+++ presentations/slides/intro/yajax.xml Mon Apr 17 08:14:08 2006
@@ -2,4 +2,8 @@
<break lines="1" />
<example title="yajax.php" filename="yajax.php" hide="0"
result="0" fontsize="1.5em" marginright="0em"/>
<example title="" filename="yajax.php" hide="1"
result="1" marginright="0em" type="iframe"/>
+<example title="yajax_geocode.php" filename="yajax_geocode.php"
hide="0" result="0" fontsize="1.5em" marginright="0em"/>
+<example title="" filename="yajax_geocode.php" hide="1"
result="1" marginright="0em" type="iframe"
iheight="100"/>
+<example title="yajax_combined.php" filename="yajax_combined.php"
hide="0" result="0" fontsize="1.5em" marginright="0em"/>
+<example title="" filename="yajax_combined.php" hide="1"
result="1" marginright="0em" type="iframe" iheight="400"
iwidth="2000"/>
</slide>
http://cvs.php.net/viewcvs.cgi/presentations/slides/intro/yajax_combined.php?view=markup&rev=1.1
Index: presentations/slides/intro/yajax_combined.php
+++ presentations/slides/intro/yajax_combined.php
<?php
if(!empty($_GET['loc'])) {
$geo = 'http://api.local.yahoo.com/MapsService/V1/geocode?appid=YahooDemo'.
'&location='.urlencode($_GET['loc']).'&output=php';
$ll = unserialize(file_get_contents($geo));
$lat = $ll['ResultSet']['Result']['Latitude'];
$lon = $ll['ResultSet']['Result']['Longitude'];
$map = "http://api.local.yahoo.com/MapsService/V1/mapImage?appid=YahooDemo".
"&output=php&image_width=500&image_height=500&radius=1500";
$N = unserialize(file_get_contents("$map&latitude=$lat&longitude=$lon"));
$lat = -$lat; $lon = $lon<0 ? 180+$lon : $lon-180;
$S = unserialize(file_get_contents("$map&latitude=$lat&longitude=$lon"));
header("Content-type: application/x-json");
echo
json_encode(array('north'=>$N['Result'],'south'=>$S['Result']));
exit;
}
?>
<html><head>
<script language="javascript" src="/yui/YAHOO.js"></script>
<script language="javascript" src="/yui/connection.js"></script>
<script language="javascript">
<!--
var img1 = false;
var img2 = false;
var fN = function callBack(o) {
var resp = eval('(' + o.responseText + ')');
if(!img1) {
img1 = document.createElement('img');
img1.src = resp.north; img1.width=500; img2.height=500; img2.border=1;
document.body.appendChild(img1);
} else img1.src = resp.north;
if(!img2) {
img2 = document.createElement('img');
img2.src = resp.south; img2.width=500; img2.height=500; img2.border=1;
document.body.appendChild(img2);
} else img2.src = resp.south;
}
var callback = { success:fN }
function sendform(target,formName) {
YAHOO.util.Connect.setForm(formName);
YAHOO.util.Connect.asyncRequest('GET',target,callback);
}
// -->
</script>
</head><body>
<form name="main"
action="javascript:sendform('yajax_combined.php','main')">
Location: <input type="text" name="loc" />
</form>
<div id="result"></div>
</body></html>
http://cvs.php.net/viewcvs.cgi/presentations/slides/intro/yajax_geocode.php?view=markup&rev=1.1
Index: presentations/slides/intro/yajax_geocode.php
+++ presentations/slides/intro/yajax_geocode.php
<?php
if(!empty($_REQUEST['loc'])) {
$src = 'http://api.local.yahoo.com/MapsService/V1/geocode?appid=rlerdorf'.
'&location='.urlencode($_REQUEST['loc']).'&output=php';
header("Content-type: application/x-json");
echo json_encode(unserialize(file_get_contents($src)));
exit;
}
?>
<html><head>
<script language="javascript" src="/yui/YAHOO.js"></script>
<script language="javascript" src="/yui/connection.js"></script>
<script language="javascript">
<!--
var fN = function callBack(o) {
var resp = eval('(' + o.responseText + ')');
var latlon = document.getElementById('latlon');
latlon.innerHTML = "Latitude: <b>"+resp.ResultSet.Result.Latitude+"</b>
"+
"Longitude:
<b>"+resp.ResultSet.Result.Longitude+"</b><br />"+
"Precision:
<b>"+resp.ResultSet.Result.precision+"</b>";
}
var callback = { success:fN }
function sendform(target,formName) {
YAHOO.util.Connect.setForm(formName);
YAHOO.util.Connect.asyncRequest('POST',target,callback);
}
// -->
</script>
</head><body>
<form name="main"
action="javascript:sendform('yajax_geocode.php','main')">
Location: <input type="text" name="loc" />
</form>
<div id="latlon">
</div>
</body></html>