


































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
PHP class notes-unit 5 syllabus: AJAX - Advanced AJAX.
Typology: Lecture notes
1 / 42
This page cannot be seen from the preview
Don't miss anything!



































Writing AJAX program: Program 5- Index.html
An Ajax demo
403 – Forbidden. 404 – Not found. 502 – Bad Gateway. 503 – Service Unavailable.
The php code: datas.php
In the AJAX program index.html,
On running the index.html file, the onclick event of the button will call the php file and the output is displayed.
Sending Ajax data with POST
Sending Ajax data with POST
_ _
The fetched message will appear here.
In the above program,
_
Soda Cheese Salami
Store.html
Using Ajax with XML
XMLHttpRequestObject.send(null); } }
function getproducts2() { if(XMLHttpRequestObject) { XMLHttpRequestObject.open("GET", "products2.xml?b=t");
XMLHttpRequestObject.onreadystatechange = function() { if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) { var xmlDocument = XMLHttpRequestObject.responseXML; products = xmlDocument.getElementsByTagName("item"); listproducts(); } }
XMLHttpRequestObject.send(null); } }
function listproducts () { var loopIndex; var selectControl = document.getElementById('productsList');
onclick = "getproducts1()">
Your selection will appear here.
document.getElementById (‘targetDiv’).inner HTML = “You Selected” + Products [document.getElementByID (‘ProductsList’). SelectedIndex]. firstChild.data;
Using Ajax with XML
XMLHttpRequestObject.open("GET", "products.php?items=2&t=4");
XMLHttpRequestObject.onreadystatechange = function() { if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) { var xmlDocument = XMLHttpRequestObject.responseXML; products = xmlDocument.getElementsByTagName("item"); listproducts(); } }
XMLHttpRequestObject.send(null); } } function listproducts () { var loopIndex; var selectControl = document.getElementById('productsList');
for (loopIndex = 0; loopIndex < products.length; loopIndex++ ) { selectControl.options[loopIndex] = new Option(products[loopIndex].firstChild.data); } }
function setproducts() { document.getElementById('targetDiv').innerHTML =
"You selected " + products[document.getElementById ('productsList').selectedIndex].firstChild.data; }
Using Ajax with XML
your selection will appear here.
In the above program,
if (XMLHttpRequestObjects[index].readyState == 4 && XMLHttpRequestObjects[index].status == 200) { var xmlDocument = XMLHttpRequestObjects[index].responseXML; products = xmlDocument.getElementsByTagName("item"); listproducts(); } } XMLHttpRequestObjects[index].send(null); } }
In the above code,