/    Sign up×
Community /Pin to ProfileBookmark

Problem with AJAX in Firefox

Hi,

I have the following source –

[code]
<input type=”text” name=”foo” id=”foo” onkeyup=”doThis(this.value);”/>
[/code]

(this is the html)

[code]
function createRequestObject() {
var req;
if(window.XMLHttpRequest){
req = new XMLHttpRequest();
} else if(window.ActiveXObject) {
req = new ActiveXObject(“Msxml2.XMLHTTP”);
if (! req){
req = new ActiveXObject(“Microsoft.XMLHTTP”);
}
}
else {
alert(‘#?+*!’);
}
return req;
}
var http = createRequestObject();
function doThis(flag) {
http.open(“get”, “search.php?flag=”+flag);
http.onreadystatechange = handleResponse_doThis;
http.send(null);

function handleResponse_doThis() {
if(http.readyState == 4 && http.status == 200){
var response = http.responseText;
if(response) {
list value1
list value2
list value3
….
}
}
}
[/code]

(this is in js file)

It is quite simple ajax example – when key is pressed – k for instance – the list of values starting with ‘k’ appear in a div. It is working ok if I press always normal characters(a-z for instance). But if I press ‘%’ nothing happens. And here comes the funny(for me) part – if I just switch to other Firefox browser on my window and then come back to the search page, I see that ‘%’ worked out – I see all words displayed in the div. Why this happens only when I switch to other browser window and then switch back? It seems that some refreshing is delayed or triggered by switch to other browser window? And also strange for me – this works perfectly in IE – by typing ‘%’ list of all elements is displayed. That puts me in mind that XMLHttpRequest
make something, but I can’t find it out.
Any ideas and help?

Thanks in advance.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@KorOct 24.2007 — I guess you should escape the characters, as special characters might have other roles in the submitting process. Try
<i>
</i>http.open("get", "search.php?flag="+escape(flag));
×

Success!

Help @tarta 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 5.1,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

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