Total members 9951 | Gratitudes |It is currently Sat Feb 11, 2012 9:45 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Question
 Question subject: Sending a post request using AJAX
PostPosted: Mon Aug 06, 2007 11:05 am 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2103
Location: Earth
Has thanked: 39 time
Have thanks: 56 time

hi all ,
This application is an simple example of how you can send a POST request to an dynamic web page.Here is used php file .You can take the name of the user .Send it to the php file as a paramter and in the php file you can make the proccessing you want on it .Here i just make a echo call in the php file .In the Ajax file (html) you can take the response of your request and show it on the browser.

Here is the HTML file for the Ajax :
Code:

<html >
<script type="text/javascript">
function doAjaxPost(myform)
{

      var message="myname="+myform.elements["myname"].value;
     var url="ajaxform.php";
var request=null;

    if(window.XMLHttpRequest)   
   {

   request=new XMLHttpRequest();
   }
   else if(window.ActiveXObject)
   {

   request = new ActiveXObject("Microsoft.XMLHTTP");
   }
   
   if(request)
   {
   request.open("POST",url);
   request.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded; charset=UTF-8");

request.onreadystatechange = function() {
  if(request.readyState==0)
document.getElementById('status').innerHTML='Uninitialized';
else  if(request.readyState==1)
document.getElementById('status').innerHTML='Loading...';
else  if(request.readyState==2)
document.getElementById('status').innerHTML='Loaded';
else  if(request.readyState==3)
document.getElementById('status').innerHTML='Interactive';
else  if(request.readyState==4)
{
document.getElementById('status').innerHTML='Completed';

document.getElementById("display").innerHTML =
request.responseText;
}

}
request.send(message);
   


   
   }
   else
   document.getElementById('Txtdata').value='Nothing';
}

</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<span id='status' ></span><br/>
<form >

Name :<input type='text' size='50' name='myname'/><br/>
<input  type='button' onclick="doAjaxPost(this.form);"; value="submit"/>

</form>
<div id='display'>
</div>

</body>
</html>


And here is the PHP file :
Code:

<?

  $name
=$_REQUEST['myname'];
  
   echo
"Welcome ".$name." to AJAX world  !";
  
  
?>


i wish it will be helpful for you ,if you faced any problem while running it just reply to my post :smile:

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  


 Similar topics
 Topic title   Forum   Author   Comments 
 Sending One lakh character in ajax  AJAX  Anonymous  0
 Ajax Source code to Suggest application with JSP Server side  AJAX  msi_333  5
 [Ajax/PHP] Registration - Check for empty textboxs  AJAX  PF2G  0
 Application for the post of Network Admin.  Job Opportunities  Anonymous  0
 AJAX WITH JSP  AJAX  LAAVANYA  1

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team