xmlHttp.responseText return empty


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

Hi,

The first thing I would do is to check in your browser’s console to see if there are any error messages being reported.
How do I do that?

Hi Isy,

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:

xmlHttp.setRequestHeader("X-Requested-With", "XMLHttpRequest");

after adding

xmlHttp.setRequestHeader("X-Requested-With", "XMLHttpRequest");

xmlHttp.responseText still return empty.

What is ./scripts/phpAjaxFunction.php echoing out if you access it directly rather than vis JavaScript?

what do u means for echoing out?

I think what he means is if you go to

./scripts/phpAjaxFunction.php

in your browser, what output do you see? (including both rendered and view-source)

*hint - AJAX makes an HTTP request as does a browser

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?

I’m happy it’s executing completely for you.

But what is it’s output to your browser?

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.

it suppose to return some text in the echo, it return in my old server, after i move to new server, it is not.
i use the debugger, no error found.

Might it have something to do with same origin policy?