November, 2009

ASPNet AJAX — Works In IE But Not Firefox

It's actually a pretty frustrating problem. You get your WCF service constructed and you get your web.config all perfect and you get your client-side script running smoothly . . . in Internet Explorer. When you go to check it out in Mozilla Firefox, it doesn't work. Your server-side code never gets executed. When you check out the Firefox Error Console, you see something like this:

Error: [Exception... "'Sys.Net.WebServiceFailedException: Sys.Net.WebServiceFailedException:
The server method 'MyMethod' failed with the following error: '
when calling method: [nsIDOMEventListener::handleEvent]
"  nsresult: "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)"
location: "<unknown>"  data: no]

Don't panic. The problem is that Firefox requires both a success and a failure handler. You cannot pass null in for either one — both have to be valid functions:

<script type="text/javascript" language="javascript">
// <![CDATA[
function MyMethod()
{
    var service = new ajaxService();
    service.MyMethod("Data",OnSuccess,OnFailure,null);
}

function OnSuccess(result){ alert(result); }

function OnFailure(err){ alert(err); }

// ]]>
</script>

Add both a valid success and a valid failure handler and Firefox will function as expected.

I hope this helps someone.

 
Your feedback helps me provide content that is meaningful. Please don't be shy about speaking your mind.
Please see other tidbits.

Please provide feedback about this article

Email: (optional)