Php con ajax y mysql

Solo disponible en BuenasTareas
  • Páginas : 11 (2708 palabras )
  • Descarga(s) : 4
  • Publicado : 27 de mayo de 2010
Leer documento completo
Vista previa del texto
Leimnud Sistema de Manuales-Tutorial básico del método AJAX con...

file:///D:/Tutoriales/Tutorial%20b%E1sico%20del%20m%E9todo%2...

Tutorial básico del método AJAX con PHP y MySQL
The XMLHttpRequest object is a handy dandy JavaScript object that offers a convenient way for webpages to get information from servers without refreshing themselves. The benefit to end users is that they don'thave to type as much and they don't have to wait as long. For example, having the user's city and state show up in a webpage automatically after the ZIP code has been typed in is a big time saver. Although the XMLHttpRequest object might sound complex and different from any other JavaScript object you have ever used, it really isn't. A good way to think of the XMLHttpRequest object is as you wouldthink of the JavaScript Image object. As we know, with the Image object you can dynamically specify a new URL for the image source without reloading the page. Similarly with the XMLHttpRequest object, you can dynamically specify a URL to get some server data without reloading the page. The purpose of this article is to demonstrate through a series of baby steps just how easy it is to use theXMLHttpRequest object. In order to complete this tutorial you should have some basic PHP, MySQL and JavaScript experience. That said, the PHP programming in these examples is so basic that if you do not have PHP experience, it may still be possible for you to look at the PHP code and apply the functionality to your weapon of choice, be it PERL, ASP, or JSP.

1. Creating the Form We first create asimple webpage that has the HTML for our Web form. There is nothing out of the ordinary here - just basic HTML defining the city, state, and ZIP code. PHP [inicio]

1. 3. < head> 4. < title>ZIP Code to City and State using XmlHttpRequest 5. 6. < body> 7. < form action="post"> 8. < p> 9. ZIP code: 10. < input type="text" size="5" name="zip" id="zip" /> 11. 12. City: 13. < input type="text"name="city" id="city" /> 14. State: 15. < input type="text" size="2" name="state" id="state" /> 16. 17. 18.
PHP [fin]

1 de 14

02/06/2006 16:10

Leimnud Sistema de Manuales-Tutorial básico del método AJAX con...

file:///D:/Tutoriales/Tutorial%20b%E1sico%20del%20m%E9todo%2...

2. Adding the Event Handler We then add an onblur event handler function named updateCityState(). This eventhandler is called whenever the ZIP code field loses focus. onblur="updateCityState();" The updateCityState() function will be in charge of asking the server what the city and state is for a given Zip code. For now, this function does nothing. We will add its guts later. PHP [inicio]

1. 3. < head> 4. < title>ZIP Code to City and State using XmlHttpRequest 5. < script language="javascript"type="text/javascript"> function updateCityState() { } 6. 7. 8. 9. 10. ZIP code: 11. 15. 16. City: 17. 18. State: 19. 20. 21. 22.
PHP [fin] 3. Creating the XMLHttpRequest Object Of course we need to create an XMLHttpRequest object. Because of variations among the Web browsers, creating this object is more complicated than it need be. The best way to create the XMLHttpRequest object is to use afunction named getHTTPObject(). This function has precompile directives which make it pretty cross-browser compatible. Don't worry if the code inside the function is unclear to you. It's not important that you understand its inner workings. PHP [inicio]

2 de 14

02/06/2006 16:10

Leimnud Sistema de Manuales-Tutorial básico del método AJAX con...file:///D:/Tutoriales/Tutorial%20b%E1sico%20del%20m%E9todo%2...

3 de 14

1. 3. < head> 4. < title>ZIP Code to City and State using XmlHttpRequest 5. < script language="javascript" type="text/javascript"> 6. function updateCityState() { 7. } 8. function getHTTPObject() { 9. var xmlhttp; 10. /*@cc_on 11. @if (@_jscript_version >= 5) 12. try 13. { 14. xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 15. } 16. catch (e) 17. { 18. try...
tracking img