Forum Moderators: open

Message Too Old, No Replies

Request readyState problem with IE

         

patxiworks

12:24 pm on May 22, 2006 (gmt 0)

10+ Year Member



Hi all,

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.

jshanman

3:04 pm on May 22, 2006 (gmt 0)

10+ Year Member



XssHttpRequest?

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

patxiworks

4:12 pm on May 22, 2006 (gmt 0)

10+ Year Member



Thanks jshanman, but the script is supposed to get stuff from a server using ajax. Except if I don't understand what you're referring to, my problem is really with the output from the server.

jshanman

4:45 pm on May 22, 2006 (gmt 0)

10+ Year Member



I was refering to the XssHTTPRequest object you seem to be using. This is a custom object created to mimic the actual Javascript XmlHTTPRequest object(which is probably the reason for the strange behavior your getting).

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

patxiworks

5:04 pm on May 22, 2006 (gmt 0)

10+ Year Member



Hmm...

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".

jshanman

5:23 pm on May 22, 2006 (gmt 0)

10+ Year Member



Thats exactly what the Xss program does.

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

patxiworks

10:19 am on May 23, 2006 (gmt 0)

10+ Year Member



Thanks a lot for the insight.

I try out the script. I hope it does not give the same IE problem that using the Xss script gives. But if Xss can be boiled down to what you have posted, then I reckon that so can the normal xmlHTTPRequest. Or what is the difference?

jshanman

12:49 pm on May 23, 2006 (gmt 0)

10+ Year Member



The Xss is just an object that the author (link above) created to make cross-domain dynamic scripting ("ajax") easier and more familer. He copied all the properties and methods from the XmlHTTPRuest object to make it familer and easy to use. I think it's a great idea, but it may need more browser testing (although I really don't know if the problem you were having was because of the custom object, but it seems that way).

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

patxiworks

3:23 pm on May 23, 2006 (gmt 0)

10+ Year Member



Thank you very much for the response.

I will try to do as you suggest. As for the browser testing, it works well with Firefox and IE (I'm don't remember whether I've tested it on Opera). But thanks a lot indeed.