Total members 11895 |It is currently Sat Dec 21, 2024 3:14 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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 :
html 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:



_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Sending a post request using AJAX
 AJAX - Sending a request to a server     -  
 check request was GET or POST     -  
 Extracting Parameters from GET or POST Request     -  
 Sending One lakh character in ajax     -  
 Help Sending e-mail from VB.Net application     -  
 sending sms from bluetooth mobile to pc     -  
 sending parameters into XSLT sheet     -  
 Sending and playing microphone audio over network     -  
 What is AJAX, How to start AJAX?     -  
 sending sms using java code and bluetoth device pls send the     -  



Topic Tags

AJAX Request
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com