Search
Syndication
Sponsors

Posts Tagged ‘ajax’

The Essential Guide to Dreamweaver CS3 with CSS, Ajax, and PHP (Paperback)

Sunday, May 3rd, 2009

The Essential Guide to Dreamweaver CS3 with CSS, Ajax, and PHP

With over 3 million users worldwide, Adobe’s Dreamweaver is the most popular web development software in the world, and it just took another step forward with CS3, the new version released in 2007. Having come a long way from its humble beginnings as a simple web design tool, CS3 allows you to rapidly put together standards compliant web sites and dynamic web sites with server-side languages and Ajax, and much more. To complement this great new application, David Powers has written the ultimate guide to itThe Essential Guide to Dreamweaver CS3 teaches you everything you need to know about the application, from setting up your development environment environment to publishing your sites and applications on the web, and every (more…)

Get Dow Jones stock market data

Tuesday, March 31st, 2009

This example retrieves the latest Dow Jones data from Yahoo finance when a page is loaded

Part 1 : The all important form

<html>
<head>
<script type=”text/javascript” src=”getdow.js”></script>
</head>
<body onLoad=”showDow(this.value)”>

Latest Dow Jones data:

<div id=”dowOutput”>
<b>
</b>
</div>
</p>
</body>
</html>

Part 2 : The JavaScript which in this case is in a file called getdow.js

var xmlHttp;
function showDow(str)
 {
 xmlHttp=GetXmlHttpObject();
 if (xmlHttp==null)
  {
  alert (”Browser does not support HTTP Request”);
  return;
  }
 var url=”getdow.php”;
 url=url+”?q=”+str;
 url=url+”&sid=”+Math.random();
 xmlHttp.onreadystatechange=stateChanged;
 xmlHttp.open(”GET”,url,true);
 xmlHttp.send(null);
 }

function stateChanged()
 {
 if (xmlHttp.readyState==4 || xmlHttp.readyState==”complete”)
  {
  document.getElementById(”dowOutput”)
  .innerHTML=xmlHttp.responseText;
  }
 }function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 // Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject(”Msxml2.XMLHTTP”);
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject(”Microsoft.XMLHTTP”);
  }
 }
return xmlHttp;
}

Part 3 : Finally the PHP part which is in a file called getdow.php

<?php
//get the q parameter from URL
$q=$_GET["q"];//find out which feed was selected

$fp = fopen (”http://download.finance.yahoo.com/d/quotes.csv?s=%5EDJI&f=sl1d1t1c1ohgv&e=.csv”,”r“);
$data = fgetcsv ($fp, 1000, “,”)
?>
<!– this is our table which displays the stock info –>
<!– we access the individual items by using $data[0]–>

<table>
<br/>
<tr><td>symbol</td><td><?php echo $data[0] ?></td></tr>
<tr><td>last price</td><td><?php echo $data[1] ?></td></tr>
<tr><td>date</td><td><?php echo $data[2] ?></td></tr>
<tr><td>time</td><td><?php echo $data[3] ?></td></tr>
<tr><td>change</td><td><?php echo $data[4] ?></td></tr>
<tr><td>open</td><td><?php echo $data[5] ?></td></tr>
<tr><td>high</td><td><?php echo $data[6] ?></td></tr>
<tr><td>low</td><td><?php echo $data[7] ?></td></tr>
<tr><td>volume</td><td><?php echo $data[8] ?></td></tr>
</table>
<br/>
Data courtesy of <a href=”http://finance.yahoo.com”>Yahoo finance</a>
<?php
//close the filehandle $fp
fclose ($fp);
?>

Ajax and PHP Stock Quote example

Monday, March 30th, 2009

This is  a new source code section so we thought what could we have as a useful first example using Ajax, PHP and a bit of JavaScript. A stock ticker example. Lets go

Part 1 : Is the form itself.

<html>
<head>
<script type=”text/javascript” src=”getstock.js”></script>
</head>
<body>
<form>
Enter your stock ticker symbol:
<input type=”text” id=”txt1″ size=”30″ onkeyup=”showQuote(this.value)”>
</form><p>
<div id=”stockOutput”>
<b>
</b>
</div>
</p>
</body>
</html>

Part 2 : This is the all important Javascript, in this example it is calles getstock.js

var xmlHttp;
function showQuote(str)
 {
 xmlHttp=GetXmlHttpObject();
 if (xmlHttp==null)
  {
  alert (”Browser does not support HTTP Request”);
  return;
  }
 var url=”getstock.php”;
 url=url+”?q=”+str;
 url=url+”&sid=”+Math.random();
 xmlHttp.onreadystatechange=stateChanged;
 xmlHttp.open(”GET”,url,true);
 xmlHttp.send(null);
 }

function stateChanged()
 {
 if (xmlHttp.readyState==4 || xmlHttp.readyState==”complete”)
  {
  document.getElementById(”stockOutput”)
  .innerHTML=xmlHttp.responseText;
  }
 }function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 // Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject(”Msxml2.XMLHTTP”);
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject(”Microsoft.XMLHTTP”);
  }
 }
return xmlHttp;
}

Part 3 : The bit were interested in, the PHP code again this is called getstock.php

<?php
//get the q parameter from URL
$q=$_GET["q"];//find out which feed was selected

$fp = fopen (”http://finance.yahoo.com/d/quotes.csv?s=$q&f=sl1d1t1c1ohgv&e=.csv”,”r“);
$data = fgetcsv ($fp, 1000, “,”)
?>
<!– this is our table which displays the stock info –>
<!– we access the individual items by using $data[0]–>
<html>
<head>
</head>
<body>
<table>
<tr><td>description</td><td>latest figure</td><tr>
<tr><td>symbol</td><td><?php echo $data[0] ?></td></tr>
<tr><td>last price</td><td><?php echo $data[1] ?></td></tr>
<tr><td>date</td><td><?php echo $data[2] ?></td></tr>
<tr><td>time</td><td><?php echo $data[3] ?></td></tr>
<tr><td>change</td><td><?php echo $data[4] ?></td></tr>
<tr><td>open</td><td><?php echo $data[5] ?></td></tr>
<tr><td>high</td><td><?php echo $data[6] ?></td></tr>
<tr><td>low</td><td><?php echo $data[7] ?></td></tr>
<tr><td>volume</td><td><?php echo $data[8] ?></td></tr>
</table>
<?php
//close the filehandle $fp
fclose ($fp);
?>

Want to see what it looks like, visit the link and start typing a ticker symbol (MSFT, GOOG are a 2 examples)

http://www.getphp.net/ajaxexamples/stock/stockform.php

Note if you use this add in a credit to Yahoo for kindly supplying the data.

P.S

We’ll discuss how this all works at a later date

Sample Chapter : AJAX and PHP Building Responsive Web Applications

Saturday, March 21st, 2009
AJAX and PHP Building Responsive Web Applications

AJAX and PHP Building Responsive Web Applications

This is a sample chapter from the book AJAX and PHP Building Responsive Web Applications, we offer you chapter 1 which is entitled AJAX and the Future of Web Applications.

Overview

Chapter 1: AJAX and the Future of Web Applications is an initial incursion into the world of
AJAX and the vast possibilities it opens up for web developers and companies, to offer a better
experience to their users. In this chapter you’ll also build your first AJAX-enabled web page,
which will give you a first look of the component technologies.

You can buy AJAX and PHP Building Responsive Web Applications in either Ebook or hard book copy here

  AJAXandPHPBuildingResponsiveWebApplications (497.4 KiB, 92 hits)