Wednesday, March 28, 2012

Atlas web service proxy undefined - bug or mistake?

Ok, here's the deal: I have javascript method that is called on the window's load event:

window.onload = function () { getDataForTable();};

Pretty striaghtforward, right? Well, when the getDataForTable method executes it calls an Atlas proxy method:

WebServices.Callbacks.CalendarFunctions.CheckDate(dateField.value, getDataForTable_Callback);
But when the script execute on load, I get an error stating that 'WebServices' is not defined. When I check the HTML output the Atlas javascript reference is there: "text/xml-script">"http://schemas.microsoft.com/xml-script/2005"> <references> <add src="http://pics.10026.com/?src=/Anthem/Callback/CalendarFunctions.asmx/js"/> "text/xml-script">"http://schemas.microsoft.com/xml-script/2005"> <references> <add src="http://pics.10026.com/?src=/Anthem/Callback/CalendarFunctions.asmx/js"/>
<script type="text/xml-script"><page xmlns:script="http://schemas.microsoft.com/xml-script/2005"> <references> <add src="/Anthem/Callback/CalendarFunctions.asmx/js" /> </references> <components /></page></script>
And when I hit the URL above the javascript there looks correct:
Type.registerNamespace('WebServices.Callbacks'); WebServices.Callbacks.CalendarFunctions=new function() {this.path = "http://localhost:64408/Project/Callback/CalendarFunctions.asmx"; this.appPath = "http://localhost:64408/Anthem/"; var cm=Sys.Net.ServiceMethod.createProxyMethod; cm(this,"CheckDate","date"); }

So... here is the question: why is this undefined? I think this is a bug because when I debug the script the ".asmx/js" script is not loaded in the script explorer window like other referenced scripts. So, any work arounds? How else do I get this call to execute during the window.onload event?

Thanks in advance for the help.

The best thing to do I think is to install something like fiddler, and verify that the request going out is in the form you expect, and that you are indeed getting the javascript that you get when you use the script include. Hopefully you'll see something obvious...

Actually I think this might be a timing issue, you are probably calling your onLoad before atlas has a chance to load its scripts, so you can verify that is the case in fiddler. Anyways you probably want to register your getDataForTable on pageLoad or using atlas's ApplicationOnLoad.

Hope that helps,
-Hao


You are right, I added the getDataForTable method after I posted this and it worked - it was just a timing issue. Thanks for the help though!

No comments:

Post a Comment