PHP: implementing a heavy use of AJAX
Today, the trend is to implement AJAX in everything related with Web. AJAX (Asynchronous JavaScript and XML) is not a new programming language, It is a “style” of development that mix two technologies, the client side (JavaScript) and the server site (usually PHP, JSP, Java or other).
The client side could request just a part of the page instead of download the hole page. Until this point everything is good, but not always is so good, such benefits needs more development, and AJAX is not well standarized.
Let’s start with AJAX:
Basic Example
Html:
<!– Clicking this link initiates the asyncronous request –> <a href=“javascript:void(0)” onclick=“supportAjax && sayHello();”>Say Hello</a><br /> <!– used to display the results of the asyncronous request –> <span id=“span_result”></span>
Javascript:
var supportAjax;function createAjaxObj() { supportAjax=true; if (window.XMLHttpRequest) { return new XMLHttpRequest(); //Not IE } else if(window.ActiveXObject) { return new ActiveXObject(“Microsoft.XMLHTTP”); //IE } else { supportAjax=true; } } var receiveReq = createAjaxObj(); function sayHello() { //If our XmlHttpRequest object is not in the middle //of a request, //start the new asyncronous call. if (receiveReq.readyState == 4 || receiveReq.readyState == 0) { //Setup the connection as a GET call to //SayHello.php. //True explicity sets the request //to asyncronous (default). receiveReq.open(“GET”, ‘SayHello.php’, true); //Set the function that will be called when the //XmlHttpRequest objects state changes. receiveReq.onreadystatechange = handleSayHello; //Make the actual request. receiveReq.send(null); } } //Called every time our XmlHttpRequest objects state changes. function handleSayHello() { //Check to see if the XmlHttpRequests state is finished. if (receiveReq.readyState == 4) { //Set the contents of our span element to // the result of the asyncronous call. elem = document.getElementById(’span_result’); elem.innerHTML = receiveReq.responseText; } }
As you can see write AJAX pages is not so short, Image that you have to do a Web Portal such as Yahoo Mail, Gmail, or something else that require a heavy use of AJAX.
I usually work with Javascript class that made easy develop AJAX apps.
And Here is an example how to implement this JS class:
<script language=“JavaScript1.1“ src=“ajax.js“></script> <script language=“JavaScript1.1“> function ajax_process_ok(obj) { //do something, the text // is in “obj.responseText” } function ajax_process_err(obj) { //do something } /* * This is the function that has the ajax function */ function AjaxQuery() { //sucess function handler var success = function(t){ajax_process_ok(t);} //error function handler var failure = function(t){ajax_process_err(t);} var url = “./hellopage.php“; var myAjax = new Ajax.Request(url, { method:‘get‘, onSuccess:success, onFailure:failure } ) } </script>
BTW, there exist others simplest method to write AJAX Apps, but I dont know to use it, I reccoment to visit PHP: Writing XAJAX and Smarty Templates
Also I’ve listening many goods things about scriptaculous, prototype, and don´t forgot to check these too
Also I recomment to see the PHP AJAX Section
- Hippo AJAX Form: Generate HTML forms and submit via AJAX.
- True Color Picker: Present a palette to let the user pick colors.
- AJAX Edit In Place: Edit and save a paragraph of text in an HTML page.
- AJAX File Uploader: Browse files uploaded without page reloading.
- AJAX Grid: Edit and save table data without page refreshing.
- Auto complete: Auto-complete text typed in a form input.
- Suggester: Complete text typed in form inputs using AJAX
The entrepreneurs of the modern age are enhancing their business scope in the global world via online marketing tactics. The best option of promoting your business products is email marketing by which you may approach the potential clients. The proper pay per click management services of search engine optimizers are offered in the different rates to the clients. The best strategies of internet advertising are applied by professional advertisers to run advertising campaign successfully.
Share and Enjoy:
These icons link to social bookmarking sites where readers can share and discover new web pages.
July 5th, 2007 at 5:33 pm
php y AJAX…
Como comenzar con AJAX y PHP, varios ejemplos……
July 5th, 2007 at 5:35 pm
php y AJAX…
Como comenzar con AJAX y PHP, varios ejemplos……
July 6th, 2007 at 10:32 am
[…] Como comenzar con AJAX y PHP, varios ejemplos…» noticia original […]
July 13th, 2007 at 6:32 pm
This a test for proof the new captcha!
July 23rd, 2007 at 8:41 am
I have page with refreshing frames. It refreshes every 1 minute. I want to make this refresh through AJAX. How can I proceed?
July 23rd, 2007 at 1:34 pm
Give me the URL of your site and I will help you
October 31st, 2007 at 12:44 am
To know more about AJAX and its usage, you can visit my blog at:
http://rochakchauhan.com/blog/category/programming/ajax/
December 27th, 2007 at 4:35 pm
Si César habla español, sería mejor que escribiera en español, antes que inglés, pues hay mucha documentación en inglés, mas los hispanos merecen acceder a la información más fácil para aprender mejor y superar el subdesarrollo en comunidad.