1 / 14

Ajax/Xajax

Ajax/Xajax. Ajax. Ajax – Asynchronous Javascript And Xml By using ajax we can internally request the server and get the response without page reloading. Ajax syntax. function testFunction() { if(window.XMLHttpRequest) { Var xmlHttp=new XMLHttpRequest(); } else {

jayers
Download Presentation

Ajax/Xajax

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Ajax/Xajax

  2. Ajax Ajax – Asynchronous Javascript And Xml By using ajax we can internally request the server and get the response without page reloading

  3. Ajax syntax function testFunction() { if(window.XMLHttpRequest) { Var xmlHttp=new XMLHttpRequest(); } else { Var xmlHttp= new ActiveXObject("Microsoft .XMLHTTP"); } xmlHttp.onreadystatechange = function() { if(xmlHttp.readyState ==4 && xmlHttp.status ==200) { //coding for the process } } xmlHttp.open(“GET”,”url”,true); xmlHttp.send(); }

  4. Ajax • In this sytax true - asynchronous false - synchronous • GET method is more faster then POST method in ajax. • While passing more values we should use POST method. • Here readystate 4 means success.

  5. Ajax Example HTML codings:- <html> <body> <p><b>Start typing a user name in the input field below:</b></p> <form> User name: <input type="text" id=”userName” name=”userName”> <input type=”button” onclick=”testFunction()”> </form> <div id=”result”></div> </body> </html>

  6. Ajax Example Script Coding:- function testFunction(){ Var xmlHttp; var userName=document.getElementById("userName").value; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlHttp=new XMLHttpRequest(); }else {// code for IE6, IE5 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlHttp.readyState==4 && xmlHttp.status==200) { document.getElementById("result").innerHTML=xmlHttp.responseText; } } xmlHttp.open("GET","display.php?userName="+userName,true); xmlHttp.send(); } Ajax Example Ajax Example

  7. Ajax Example Script Coding:- function testFunction(){ Var xmlHttp; var userName=document.getElementById("userName").value; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlHttp=new XMLHttpRequest(); }else {// code for IE6, IE5 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlHttp.readyState==4 && xmlHttp.status==200) { document.getElementById("result").innerHTML=xmlHttp.responseText; } } xmlHttp.open("GET","display.php?userName="+userName,true); xmlHttp.send(); } Ajax Example Ajax Example

  8. Ajax Example PHP coding:- <?php $ipAddress=$_SERVER['REMOTE_ADDR']; $userName=$_REQUEST['userName”]; echo “Welcome “.$userName.” . Your IP address is ” .$ipAddress; ?>

  9. Xajax • Xajax is a framework. • xajax is an open source PHP class library implementation of Ajax that gives developers the ability to create web-based Ajax applications using HTML, CSS, JavaScript, and PHP. Applications developed with xajax can asynchronously call server-side PHP functions and update content without reloading the page.

  10. Xajax xajax is designed to be extremely easy to implement in both existing web applications as well as new projects. You can add the power of xajax to nearly any PHP script in seven easy steps: 1. Include the xajax class library: require_once("xajax_core/xajax.inc.php"); 2. Instantiate the xajax object: $xajax = new xajax(); 3. Register the names of the PHP functions you want to be able to call through xajax: $xajax->registerFunction("myFunction");

  11. Xajax 4. Write the PHP functions you have registered and use the xajaxResponse object to return XML commands from them: function myFunction($arg) { $newContent = "Value of \$arg: ".$arg; // Instantiate the xajaxResponse object $objResponse = new xajaxResponse(); // add a command to the response to assign the innerHTML attribute of // the element with id="SomeElementId" to whatever the new content is $objResponse->assign("SomeElementId","innerHTML", $newContent); //return the xajaxResponse object return $objResponse; }

  12. Xajax 5. Before your script sends any output, have xajax handle any requests: $xajax->processRequest(); 6. Between your tags, tell xajax to generate the necessary JavaScript: <?php $xajax->printJavascript(); ?> 7. Call the function from a JavaScript event or function in your application: <div id="SomeElementId"></div> <button onclick="xajax_myFunction('It worked!');">

  13. Xajax The xajax hava a many commands they are below

  14. Xajax Command for getting the form values xajax.getFormValues('formName');

More Related