/    Sign up×
Community /Pin to ProfileBookmark

Problems with XMLHttpRequest.open()

Hi all,

Longtime lurker, first time poster. ?

I have a conundrum. I’m using a very simple AJAX script to open an external data file (a plain HTML page, really) and I’ve run into quite the head scratcher. I’ll post the relevent code below, but basically, everything works in IE/FF/Safari on our local development box, but when we push it out live to the internet and people access it from offsite servers, it fails in FF/Safari while continuing to work in IE. But it doesn’t fail for us in production, perhaps because our production/live servers are on the same physical network as we are. So it seems to be failing on the XMLHttpRequest.open() function, but again, only in FF/Safari. Any ideas?

(This code is included in the base HTML page and called via a form)

[CODE]function init(url, target) {
document.getElementById(target).innerHTML = ‘ Retrieving Data…’;
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
req = new ActiveXObject(“Microsoft.XMLHTTP”);
}
if (req != undefined) {
req.onreadystatechange = function() {initDone(url, target);};
req.open(“GET”, url, false);
req.send(“”);
}
}

function initDone(url, target) {
if (req.readyState == 4) { // only if req is “loaded”
if (req.status == 200) { // only if “OK”
document.getElementById(target).innerHTML = req.responseText;
} else {
document.getElementById(target).innerHTML=”     Error:n”+ req.status + “n” +req.statusText;
}
}
}

function load(name, div, from, to) {
if (from == “” || to == “”) {
document.getElementById(div).innerHTML = “     Please select both From and To…”;
} else {
init(name,div);
return false;
}
}[/CODE]

And I’m calling it with an <Input> as below:

[CODE]<input type=”image” name=”searchBtn” src=”/images/go.gif” id=”searchBtn” value=”GO” style=” ” o
nclick=”load(‘/includes/menu.html’,’my_menu’, document.drop_list.Category.value, document.drop_list.SubCat.value);return fal
se;”/>
[/CODE]

Thanks a bunch for looking. Feel free to ask any follow-up questions.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@_kidonFeb 06.2008 — Hello,

did you find any solution for this? I read something like using JSON or so..

i appreciate your help.

Thank you!
Copy linkTweet thisAlerts:
@A1ien51Feb 06.2008 — Install Firebug [http://www.getFirebug.com]">http://www.getFirebug.com] and enable it to show the XMLHttpRequest and see what is happening.

Eric
×

Success!

Help @c66979 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,
)...