/    Sign up×
Community /Pin to ProfileBookmark

XMLHTTPRequest ResponseText is blank?

Hi,

For some reason, with the following snippet, I am always getting an
empty string in request.responseText (testing in FF 3.5) – any ideas?

I verified that the URI returns a value – here is a sample URI:

[url]http://www.gamechalk.com/simulator/simulator.php?req=Simulator%20coming%20soon!%20SMS%20Zork%20to%2041411%20to%20play.&user=100[/url]

var request = null;
function postCommand()
{
var uri = “http://www.gamechalk.com/simulator/simulator.php“;
var cmd = document.getElementById(“command”).value;
var user = “100”;
uri += “?req=” + escape(cmd) + “&user=” + user;
if (request != null && request.readyState != 0 &&
request.readyState != 4)
{
request.abort();
}
try
{
request = new ActiveXObject(“Msxml2.XMLHTTP”);
}
catch (e)
{
try
{
request = new ActiveXObject(“Microsoft.XMLHTTP”);
}
catch (E)
{
request = false;
}
}
if (!request && typeof XMLHttpRequest != ‘undefined’)
{
request = new XMLHttpRequest();
}
request.open(“GET”, uri, true);
request.onreadystatechange = function()
{
if (request.readyState == 4)
{
alert(request.responseText);
}
};
request.send(null);
}

Thanks in advance.

Raj

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@KorJul 08.2009 — You need to check the [B]status[/B] property as well:
<i>
</i>if (request.readyState == 4){
[COLOR="Blue"]if (request.status==200){[/COLOR]
alert(request.responseText);
[COLOR="Blue"]}[/COLOR]
}
Copy linkTweet thisAlerts:
@raazzzinauthorJul 11.2009 — I figured out my issue.

In my ajax request, I had www.gamechalk.com but the URL I loaded in the browser was gamechalk.com (w/o the www.)

Since that would be cross-domain scripting, the browser was blocking it but not displaying any error which made it quite painful to debug :/

Hope this helps others.

Raj
×

Success!

Help @raazzzin spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...