views:

586

answers:

2

I'm having a problem with some code I've written. I've had to anonymize it, but I can give the problem. This javascript runs inside an iframe, and is part of an object that gets instantiated. The problem in particular is that I get a repeating error every time that "Type 'Object' Cannot be converted to type 'Function'" in the invoke() call. However, in the IE8 developer addon, checking the typeof of the function I pass (this.AJAXCallback), it clearly says that it's a function being passed. Is there any particular reason this error might be occurring?

MyObject.prototype.AJAXCallback=function(Data, e){
    //snip
};

MyObject.prototype.Init=function(){
    var a = window.top.window.Sys.Net.WebServiceProxy.invoke('/Data.asmx', 'GetData', false, { "IDCode":0 }, this.AJAXCallback, null);
    //snip
};
A: 

It may be giving issues because the Callback is a prototype. Have you tried wrapping the callback in an anonymous function call.

MyObject.prototype.Init=function(){
    var a = window.top.window.Sys.Net.WebServiceProxy.invoke('/Data.asmx', 'GetData', false, { "IDCode":0 }, function(data,e) { 
       this.AJAXCallback(data,e); 
    }, null);
    //snip
};
bendewey
I did try replacing it with an empty function as below, but I got the same error nonetheless:var a = window.top.window.Sys.Net.WebServiceProxy.invoke('/Data.asmx', 'GetData', false, { "IDCode":0 }, function(a,b) { ;}, null);
Sukasa
+1  A: 

I found the problem, and it doesn't seem to be on my part. I disabled debugging in the web.config file, and the error stopped. It also came back after debug was turned on, so I think it's safe to say that the debug code didn't work as well with what I wrote as the non-debug code did. In particular, it was one of the scriptmanager's JS files.

Sukasa