PHP Code:
<script>
function GetXmlHttpObject(){
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}
function createRequestObject() {
var xmlhttp;
try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); }
catch(e) {
try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
catch(f) { xmlhttp=null; }
}
if(!xmlhttp&&typeof XMLHttpRequest!="undefined") {
xmlhttp=new XMLHttpRequest();
}
return xmlhttp;
}
function doRequest(url,method,data,_handler){
http=createRequestObject()
if (http==null)
alert ("Browser does not support HTTP Request.");
http.open(method, url);
http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
http.onreadystatechange = _handler;
if(method == "POST"){
if(data == null){
alert("No data provided to post");
}else{
http.send(data);
}
}else{
http.send(null);
}
}
</script>
Include the above script and use "doRequest" function.
Example:
PHP Code:
var post_data = "field1=1&field2=2";
doRequest("populateCombo.php","POST",post_data,'my_handler');
functon my_handler(){
if((http.readyState == 4)&&(http.status == 200)){
var response = http.responseText;
}
}
Bookmarks