Wednesday, August 26, 2009

Indian Wedding Invitations In Brampton

Starting with PHP and some AJAX

Starting with PHP and Ajax, and n this article we will see the use of scripting language PHP as client-server applications using Apache as the web server some html and javascript, are going to keep everything in a simple reaching

AJAX Introduction

Well first of all let's see php, like other tools we use, apache
, html, javascript AJAX, and MySQL famosillos but this makes sense when technologies come together:

In this way the web server (Apache) allows us to interact with the motor Database (MySQL) using a script language (php) returning customer requests according to an information or other thus forming dynamic pages based on client requests and server responses. The client is nothing more than your web browser (Firefox) that gives us support for HTML and JavaScript.

Installation

Within the installer what is windows quick and recommend that we avoid a lot of hand to put him an example configuration is Appserv there is another package that We provide those tools together already configured and ready to work , now that if we are in Linux can download them separately each tool, this series just for the installation command:

apt-get install apache2 apt-get

install php5 apt-get install mysql-server-5.0
apt-get install php5-mysql
apt-get install libapache2-mod-php5

apt-get install phpmyadmin


In the first three lines are the basic tools for our web server, the other two are what we are linked together and the last is a frontend of our base manager data (this is also found in Appserv), if all went well until now we can type in your web browser as follows:
localhost / phpmyadmin from here we can manage our MySQL, create users, databases data, etc.

Interaction tools

Now let's start with a small example in php:





this small example will print 10 times the word synergy, for more details on programming in php can view this league.

now see an example of connection to a MySQL database, but first we will create our base

Snipplr


and now the code to interact with it:




As we connect the procedure involves using a source (the local host in this case), user (login1), and password (password1) if no successful connection to exit the script with an error message, if the connection is achieved chose to base we connect (test), then perform a query and display each field on the page , to finish closing the flow to the connection, to dig deeper into the php-mysql functions please see the following page .


now see an example of using AJAX, but to not go cold on the subject say that AJAX is the combination of several technologies that allow us to recharge so that asynchronous dynamics is not full page refresh if not just part of it, an example is email GMail and many more.

The first code submitted is responsible for displaying the initial screen using HTML code, we see that within the code HTML code is php from here we see to be interpetado after the browser as the php code never see but only the result of this, we create an element called div javascript pass through to the inside of this div servior see there is a text field and off the see a button that links to a javascript function, note that the code can be mixed with HTML as long as they do for separation by using tag.



The second code is the one that creates the interface between the client and the server, find the start nuevoAjax function we create the XMLHTTPRequest element, the second function is the function name where using the DOM make use of HTML elements and get their values; the Open method of our object gives us the pattern ajax of how to bind asynchronously, to file and that will lead you step method parameters it will, in this case POST, and you specify with the true that it is an asynchronous call, we have also the onreadystatechange event listener which was shot in the asynchronous call is done, so that "we will stick" the HTML that we send our server to our div (div noted previously that the way to the variable results) and the number 4 indicates that the transfer is completed successfully, with the method setRequestHeader send Content-type attribute indicating the contents of the file, finally use the send method to send as a parameter to the value of the textfield to the server, if will send non-null parameters.



Now we have the last file is the one side of the server this file is called by us. Js file using the open method is charged with the send method is called, this file contains HTML code that is sent through php creates a table and are created rows and columns using two nested for the second for use within the predefined variable $ _POST ["variable"] variable that we serve to capture the information previously sent from our js code and all that we throw (to throw everything I mean to send echo) this file is sent to the js file and sticking to the div object (remember the event handler onreadystatechange ).

and there you have it, our first example using AJAX, I hope you have been at least somewhat clear.

Conclusion:

As we have seen the use of scripting languages \u200b\u200bare increasing and how they are interacting we can navigate a bit at the beginning and if we add the management of the database from one of them it becomes a bit tangled, but After entering this, just a matter of practice.

Links:
http://www.tufuncion.com/tutorial_basico_ajax
http://www.cristalab.com/tutoriales/introduccion-a-ajax-con-php-y-formularios-c165l/
http://www.librosweb.es/ajax/capitulo7/interaccion_con_el_servidor.html
http://www.lugmen.org.ar/pipermail/lug-list/2005-May/035613.html
http://www.webestilo.com/php/php09b.phtml



1 comments:

nhakhoalavita.blogspot.com said...

Các sản phẩm với ưu điểm vượt trội ao gia dinh dep sản phẩm ao thun in thoi trang sản phẩm ao phong tron dep sản phẩm ao doi re dep với giá cạnh tranh nhất thị trường
Các sản phẩm với ưu điểm vượt trội ao gia dinh dep sản phẩm ao thun in thoi trang sản phẩm ao phong tron dep sản phẩm ao doi re dep với giá cạnh tranh nhất thị trường

Post a Comment