EdwardKing (2) [Avatar] Offline
#1
I use IE7.0 to run listing3.1,when I run this statement,like follows:
var s=new net.ConentLoader("index.html",myFunc());

I know ConentLoader will call loadXMLDoc
loadXMLDoc:function(url,method,params,contentType){
...
this.req.onreadystatechange=function(){
loader.onReadyState.call(loader);
}
...
},
...
}
function myFunc(){
alert('ok');
}

but I find when execute loader.onReadyState.call(loader),IE7.0 raise javascript error,like follows:
error:can't assign error
code:0

Why raise above error? It can't run in IE7.0? How to correct above code to run under IE7.0?

Thanks!
Pascarello (208) [Avatar] Offline
#2
Re: loadXMLDoc on listing 3.1 in page 74 can't run under IE7
The problem I see is here:
var s=new net.ConentLoader("index.html",myFunc());

There is a difference between myFunc() and myFunc

myFunc() - executes the function right than and there
myFunc - assigns a reference to that function

so it should be
var s=new net.ConentLoader("index.html",myFunc);

Eric
EdwardKing (2) [Avatar] Offline
#3
Re: loadXMLDoc on listing 3.1 in page 74 can't run under IE7
I have modify it as you tell me,like follows:
var s=new net.ConentLoader("index.html",myFunc);

But it still raise above error! Why?
davecrane (149) [Avatar] Offline
#4
Re: loadXMLDoc on listing 3.1 in page 74 can't run under IE7
Hi Edward,

Not sure if it's the root of the problem or not, but you might try to simplify iour code a little, as follows

loader.onReadyState.call(loader);

can be written more simply as

loader.onReadyState();

(historical reasons why it's written the way it is - I originally passed the XHR object as the first arg to call(), then changed it to loader, and didn't realise I could simplify it in time)

The two statements should be identical, though - I don't see why it's giving an error there.

Do you have a Javascript debugger? The free one from Microsoft for IE works OK - google for 'Microsoft Script Debugger'. If you have FrontPage or Visual Studio, then the script editor is a bit nicer to use. Or, if you can post a demo onto the internet, I'll point my debugger at it... smilie

You might also try assigning the onreadystatechange after calling open() but before send(). IE can be fussy about the call order of these, but typically only when reusing an XHR object, which we aren't doing here...

HTH

Dave