Jump to content

Ajax +post data


bob_the _builder

Recommended Posts

Hi,

 

Ajax?

 

function AjaxRequest(target_div,file,check_div)
{
var MyHttpRequest = false;
var MyHttpLoading = '<table height="238" width="100%" border="0"><tr><td align="center" valign="middle"><img src="./loading.gif"></td></tr></table>';
var ErrorMSG = 'Sorry - No XMLHTTP support in your browser, buy a newspaper instead';

if(check_div)
{
var check_value = document.getElementById(check_div).value;
}
else
{
var check_value = '';
}



if(window.XMLHttpRequest)
{
try
{
MyHttpRequest = new XMLHttpRequest();
}
catch(e)
{
MyHttpRequest = false;
}
}
else if(window.ActiveXObject)
{
try
{
MyHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
MyHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
MyHttpRequest = false;
}
}
}
else
{
MyHttpRequest = false;
}



if(MyHttpRequest)
{
var random = Math.random() * Date.parse(new Date());

var file_array = file.split('.');
if(file_array[1] == 'php')
{
  var query_string = '?rand=' + random;
}
else if(file_array[1] == 'htm' || file_array[1] == 'html')
{
  var query_string = '';
}
else
{
  var query_string = check_value + '&rand=' + random;
}


MyHttpRequest.open("get", url_encode(file + query_string), true);


MyHttpRequest.onreadystatechange = function ()
{
if(MyHttpRequest.readyState == 4)
{
document.getElementById(target_div).innerHTML = MyHttpRequest.responseText;
}
else
{
document.getElementById(target_div).innerHTML = MyHttpLoading;
}
}
MyHttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
MyHttpRequest.send(null);
}
else 
{
document.getElementById(target_div).innerHTML = ErrorMSG;
}
}

 

As it stands I can submit links ($_GET) data and have it query the database and bring back the results within the div tags, but I cant make data sent within a form query the database and bring back results within the div tag..

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/140075-ajax-post-data/#findComment-733068
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.