Il s'agit d'un article nouveau code source alors nous avons pensé que pourrions-nous avoir un exemple utile en utilisant d'abord Ajax, PHP et un peu de JavaScript. Un exemple téléscripteur. Lets go
Partie 1: Est-ce la forme elle-même.
<html>
<head>
<script type="text/javascript" src="getstock.js"> </ script>
</ Head>
<body>
<form>
Entrez votre symbole boursier:
<input type="text" size="30" id="txt1" onkeyup="showQuote(this.value)">
</ Form> <p>
id="stockOutput"> <div
<b>
</ B>
</ Div>
</ P>
</ Body>
</ Html>
Partie 2: C'est le Javascript important tout, dans cet exemple, il est getstock.js calles
xmlHttp var;
showQuote fonction (str)
(
xmlHttp = GetXmlHttpObject ();
if (xmlHttp == null)
(
alert ("Le navigateur ne prend pas en charge HTTP Request");
retour;
)
var url = "getstock.php";
url = url + "? q =" + str;
url = url + "& sid =" Math.random + ();
xmlHttp.onreadystatechange = StateChanged;
Xmlhttp.open ("GET", url, true);
xmlHttp.send (null);
)
StateChanged fonction ()
(
if (xmlHttp.readyState == | 4 | xmlHttp.readyState == "complet")
(
document.getElementById ("stockOutput")
. XmlHttp.responseText innerHTML =;
)
) Function GetXmlHttpObject ()
(
xmlHttp var = null;
essayer
(
/ / Firefox, Opera 8.0 +, Safari
xmlHttp = new XMLHttpRequest ();
)
catch (e)
(
/ / Internet Explorer
essayer
(
xmlHttp = new ActiveXObject ("Msxml2.XMLHTTP");
)
catch (e)
(
xmlHttp = new ActiveXObject ("Microsoft.XMLHTTP");
)
)
xmlHttp retour;
)
Partie 3: Les bits sont intéressés, le code PHP à nouveau ce qu'on appelle getstock.php
<? Php
/ / Récupère le paramètre q partir de l'URL
$ q = $ _GET ["q "];// savoir quels aliments a été sélectionné
$ Fp = fopen (" $ = q & f = sl1d1t1c1ohgv http://finance.yahoo.com/d/quotes.csv?s & e "csv =.," r ");
fgetcsv $ data = ($ fp, 1000, ",")
?>
<! - C'est notre tableau qui affiche les informations de stock ->
<! - Nous avons accès à chacun des points en utilisant $ data [0] ->
<html>
<head>
</ Head>
<body>
<table>
<<tr> Description <td> / td> <td> derniers chiffres / td> <tr>
<<tr> Symbole <td> / td> <td> <? Php echo $ data [0]?> </ Td> </ tr>
<<tr> <td> Dernier prix / td> <td> <? Php echo $ data [1]?> </ Td> </ tr>
<<tr> Date <td> / td> <td> <? Php echo $ data [2]?> </ Td> </ tr>
<<tr> Temps <td> / td> <td> <? Php echo $ data [3]?> </ Td> </ tr>
<<tr> Changement <td> / td> <td> <? Php echo $ data [4]?> </ Td> </ tr>
<tr> <td> ouvertes / td> <td> <? php echo $ data [5]?> </ td> </ tr>
<tr> <td> élevé </ td> <td> <? php echo $ data [6]?> </ td> </ tr>
<<tr> <td> Faible / td> <td> <? Php echo $ data [7]?> </ Td> </ tr>
<<tr> Volume <td> / td> <td> <? Php echo $ data [8]?> </ Td> </ tr>
</ Table>
<? Php
/ / Fermer le descripteur de fichier $ fp
fclose ($ fp);
?>
Vous voulez voir à quoi ça ressemble, visitez le lien et commencez à taper un symbole (MSFT, GOOG sont 2 exemples)
http://www.getphp.net/ajaxexamples/stock/stockform.php
Remarque Si vous utilisez cette extension à un crédit à Yahoo d'avoir bien voulu fournir les données.
PS
Nous verrons comment tout cela fonctionne à une date ultérieure
Pas de postes liés.
postes mis à votre disposition par Yet Another Related Posts Plugin .

[...] Une autre Ajax et PHP Stock Quote | exemple Getphp: PHP MySQL et des ressources 3. La source de données libre la plupart des solutions AJAX semblent à la base de l'application Web sur un [...] Yhaoo