function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
xmlHttp = new GetXmlHttpObject();
var url="./scripts/phpAjaxFunction.php";
var params = "action=downloadFileToUnix";
xmlHttp.open("POST", url, true);
//Send the proper header information along with the request
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
alert(trim(xmlHttp.responseText));
}
}
xmlHttp.send(params);
xmlHttp.responseText always return empty, can anyone help?
thanks in advance
Another thing to check - is your server-side script setup to check if the request was made via AJAX? Many JS libraries set the ‘x-requested-with’ header, so you could try setting this:
i can see all the function in ./scripts/phpAjaxFunction.php is executing completely, but still responseText is return empty
is there anyway to debug it?
Aside from the many good suggestions in this thread already, you could do the following (assumes you are using the Chrome browser):
Open the website where you want to inspect request and response.
Click F12.
Select the Network tab.
Here you will be able to see all requests and responses and thus pinpoint your problem.