Forum Moderators: open
I'm getting a sort of weird ajax problem with IE. Before I explain, here is the code:
function doRequest(url) {request = new XssHttpRequest();
request.open(\"GET\", url, true);
request.onreadystatechange=function() {
if(request.readyState==4) {
eval(request.responseText);
}
}
request.send(null);
//alert("loading");
}
When I this IE runs this function, it simply leaves request.readyState at 1 and doesn't do anything else. Now the weird part is that when I uncomment the alert line (at the end), it works! It sets readyState to 4 as soon as the 'OK' of the alert is clicked. Meanwhile, FF works admirably.
Does anybody have any ideas why this is happening? Thanks.
Seems like a lot of work just to do this:
var s = document.createElement("script");
s.type="text/javascript";
s.charset = "utf-8";
s.src=url;
document.appendChild(s);
then in your url, have the server page generate the javascript you to run, and have the last line of that js be a function call. When ever that function is called, you know its loaded!
- JS
If you want to use that object, you should probably ask the author about the problem... it may be a bug in his implementation.
Authors blog on [jeffreysambells.com...]
You can acheive the same effect using the code I posted, you just don't have to deal with readyState, status, and statechange stuff.
Or was the Xss just a typo?
- JS
But the XssHTTPRequest Object is supposed to help to overcome cross-scripting restrictions in ajax. From your code, I guess you're placing the script tag in the client with a call to the url where the js resides. It doesn't look like that will have the same effect as the remote server request that ajax is supposed to deal with.
It seems your code will just run a js located on another server. I want to make several calls to a server in another domain one after the other. I'm not sure whether just loading the js in the client will help to do that "dynamically".
Consider this:
function request(url) {
var s = document.createElement("script");
s.type="text/javascript";
s.charset = "utf-8";
s.src=url;
document.appendChild(s);
}
var d = new Date();
var u = "page.php?value1=1&value2=2&dt"+d.valueOf();
request(u);
function newDate(a,b) {
alert(a+" "+b);
}
Then page.php looks like this:
<?php
$v1 = $_GET{'value1'};
$v2 = $_GET{'value2'};
echo "newData($v1,$v2);";
?>
Thats the way that the Xss object works, but in it's attempt to be like XmlHTTPRequest, it over complicates a simple task. Theres nothing wrong with using it, and it won't be any slower/faster.
- JS
On the other hand, XmlHTTPRequest is a native object that is part of the browsers' Javascript implementation (IE uses ActiveX), so theres no way to "boil down" that object since its all internal.
Again, I think the Xss object is a great idea, but probably needs more testing. Whether you use it or not, it may be a good idea to email the author with your browser version, code, and problem to see if it's a bug that can be fixed.
- JS