![]() |
|
|
#1 |
|
Senior Member
Join Date: Aug 2011
Posts: 131
|
Let us try to understand about ajax call
Ajax is called in program whenever we want to extract the data from server or whenever we want to submit or post the data to server without submitting or refreshing whole web page Let us begin by creating a scripting file. In our case, we have created a php file with name ajax.php Following are few lines for ajax call PHP Code:
In HTML part, i have created to input boxes with name "book" and "result". In book text box, i have called a javascript function "ajaxFunction(this.value)" by passing text field value. Now lets study about javascript part. Depending on the browser, i have written different commands to create ajax object with name "ajaxRequest". After that i have written some HTML "please wait..." in the div so that while posting and extracting the data from server, atleast user can see that processing is going on. After that, keeping in mind the ready state of ajax request, i have captured the value returned by ajax (from server side) with the command ajaxRequest.responseText and assigned the value in "result" text field. I have used get method to post the ajax data to the server by following commands ajaxRequest.open("GET", 'ajax.php?book='+prmValue, true); ajaxRequest.send(null); Besides this, we can also use POST method (depending upon our requirement). We can also send multiple values from server side to ajax (depending upon the requiremetns). If server returns the multiple values then we can send these values by using XML or by inserting special character. In case of special character insertion, we can further split ajaxRequest.responseText values into array and use these values Cheers, code is ready to use. Just enjoy. Please feel free to ask questions on ajax call. You valuable suggestions are invited for further improvement in the coding Thanks. |
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Aug 2011
Posts: 110
|
thanx for sharing this but also share using post if you have
|
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Aug 2011
Posts: 111
|
Very useful code.
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|