var txt = http.responseText; -> it doesnt work in Chrome... how i can change this line?
Asked
Active
Viewed 87 times
1
-
No semicolons are missing, the code is valid. – elclanrs Dec 05 '13 at 00:34
-
it doesnt work in Chrome but it works in IE – user3061731 Dec 05 '13 at 00:35
-
use jQuery, that way you won't have to reinvent the wheel... Besides, your code is probably not going to be as good as theirs because for one, you'll have to deal with all sorts of browser inconsistencies, like the one you're dealing with now. – frenchie Dec 05 '13 at 00:37
-
One issue I see is that you are inferring `pageRequest` is a global variable when it looks like you want it to be scoped to your function. You should add `var pageRequest = new XMLHttpRequest();`. Not positive that is your issue, just pointing out a possibility. – marteljn Dec 05 '13 at 00:37
-
2@user3061731 You will need to provide some more information about how it fails. Open up the developer tools view. If you open up the console, do you get any errors? If you look int the networking tab, do you see the request? Is the request sent correctly? Does the response come back correctly? – Brian Campbell Dec 05 '13 at 00:38
-
2Can you explain what does or doesn't work (an error occurs, nothing happens)? Also, I would strongly recommend against using .open(_,_,false), there's almost never a good reason to make your request synchronous. – Alexis Beingessner Dec 05 '13 at 00:40
-
yeah.. nothing happens. I added some text above where you can see what exactly doesnt work in Chrom but works in IE – user3061731 Dec 05 '13 at 00:42
-
The code should work, assuming that it ends in `} http.send();` and that you have access. And if you don't have either of those, you should be seeing an error in the console. "nothing happens" is pretty hard to believe. Unless you only have `}` and no `http.send()`; but you did include it in your first code sample; and IE couldn't possibly work without it either. – Amadan Dec 05 '13 at 00:50
-
i changed http.send();))) but it doesnt work... var txt = http.responseText; alert(txt); and it is empty window))) in Chrome.. but in IE i see results)) – user3061731 Dec 05 '13 at 00:55
2 Answers
1
You should call method send at the end:
var http = new XMLHttpRequest();
var url = "http://example.com/logScore.php";
var params = "GameID=5&User="+name+"&Score="+score+"";
http.open("GET", url+"?"+params, true);
http.onreadystatechange = function() {//whatever you want}
http.send();
Without calling send request will not be send.

Steven V
- 16,357
- 3
- 63
- 76

Jerzy Pawlikowski
- 1,751
- 19
- 21
-
You probably should set .onreadystatechange *before* you send the request. – Alexis Beingessner Dec 05 '13 at 00:58
-
What do you get when you put `console.log(http.responseText);` inside onreadystatechange function? – Jerzy Pawlikowski Dec 05 '13 at 01:29
0
Doing AJAX and having it work X-Browser with vanilla-JS is a pain in the ass. I definitely recommend a library (like jQuery) to do this for you. Please see this answer for how to do it with plain JS: Easiest way to retrieve cross-browser XmlHttpRequest

Community
- 1
- 1

Zach Lysobey
- 14,959
- 20
- 95
- 149