SQL PHP HTML ASP JavaScript articles and free scripts to download
 

Ajax GET method of form Submission

We will keep a standard code sample for using in our Ajax applications. This code sample is kept as simple as possible with minimum requirements for easy understanding. This script can be developed further to have more facilities and functionalities.

Here we have used GET method of form submission where data posted in a form is taken to a backend PHP script. The PHP script is only reply back the same data string by adding a Welcome message to this.

If you are new to Ajax then try to read our previous tutorials on basics of Ajax.

Click Here to See a demo of this GET method of Ajax form submission code

<html>
<body>

<script type="text/javascript">
function ajaxFunction(str)
{
var httpxml;
try
{
// Firefox, Opera 8.0+, Safari
httpxml=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
httpxml=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
httpxml=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
function stateChanged()
{
if(httpxml.readyState==4)
{
document.myForm.time.value=httpxml.responseText;
}
}
var url="time.php";
url=url+"?txt="+str;
url=url+"&sid="+Math.random();
httpxml.onreadystatechange=stateChanged;
httpxml.open("GET",url,true);
httpxml.send(null);
}
</script>

<form name="myForm">
Name: <input type="text"
onkeyup="ajaxFunction(this.value);" name="username" />
Time: <input type="text" name="time" />
</form>

</body>
</html>




Further readings
Ajax & PHP scripts
Creating XMLHttp object in different browsers
Sample Code: Get Method of Ajax form submission
Dependant drop down list box using Ajax & PHP
Email validation using Ajax in a form
Getting customer details by entering customer id using Ajax
Progress Bar using Ajax
Progress Bar using MySQL PHP & Ajax
Displaying Message at client side using Ajax & PHP
Web page HTML form validation using Ajax and PHP
Form validation with onBlur event using Ajax and PHP

Json support in PHP
json_encode to generate Json string from PHP Array data
Json Data formatting to return database records to main script
Searching MySql database as we type using Ajax
Displaying all records based on selection of a drop down list box

Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked


Join Our Email List
Email:  
For Email Newsletters you can trust
Ajax & PHP
PHP Sections