My this blog is out of my road map, Just to give an overview on ajax with php. Im this blog I am going to use the simple ajax example no more theory just a simple way to implement the ajax in php page.
However there are so many ways to integrate the ajax with php, i.e. jquery , js, jason , xml but I am explaining a simple ajax example.
Ajax is all about to create an xmlhttprequest to the server from client browser, what it does only the specific piece of the page content goes to the server as xmlhttprequest which renders and get back to page.
Follow the steps.
what we need, 2 php page and one js file.
this is our front page,
<a id=’myid’ onclick=’ GetOrderDetail(this.id)’>Call Ajax</a> // this will call your js function, which send request to your backend page , page1.php, where you can do your server side programing,
function GetOrderDetail(id) // you are going to call this method from your page, you can send any parameter
alert(“Your Browser Donst Support Ajax”);
var url=”page1.php?id=”+id;// this is your back end page, where u render what u send from page
xmlHttp.onreadystatechange=Orderdetail_Change; you need to change the methoed name which is below
xmlHttp.open(“Get”,url,true); // nothing to change
now what you return for your page comes to this method
var _a = xmlHttp.responseText; // this your whole response from the page
document.getElementById(“order”).innerHTML=xmlHttp.responseText; //create any div where u show your data, order is the div name
paste as it is. no change in this
// Firefox, Opera 8.0+, Safari
// Internet Explorer
thats it, now come to third and last step, which is to create our backend page,
Sample , this is our back page.
Echo “this is return from ajax”;
This is only a reference, Kindly check the syntax as I am in middle of the sharpont project , and making pause on that and wrote this blog, if the is any syntax pro , so I apologize, my main reason is to provide easiest way to ajax, I will also make this ajax trick to share point 2010 website.