views:

868

answers:

3

Hi!

I am developing an application but I am having problems to get it to work in Firefox. The application recieves javascript calls from educational applications (websites that are showed in shared window) and it is supposed to return values from a .net webservice. The values must be returned in the same function that recieves the call. The webservices return values are strings that can be true,false or sometimes a value from a database. The websevice supports ajax.

Since I dont know exactly how to call a webservice using javascript I am using jquery-1.3.2.

The code bellow works on Internet Explorer but when used on Firefox it is like it wont wait for the call to return a value despite the async:fale.

function API_LMSInitialize(param)
{
  res="true";
  $.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    url: "../../../GateWay/WebService.asmx/LMSInitialize",
    data: "{'courseid':'"+courseid+"','userid':'"+userid+"'}",
    dataType: "json",
    async: false,
    success: function(msg) { res = msg; },
    error: function(){ res="false"; }
  });

  return res;
}

Any suggestions?

A: 

Probably the ajax call fails and exits through the error callback. You can add an alert to verify this or even better use Firebug and console.log.

The reason that the call succeeds with IE and fails with Firefox could have to do with the JSON data returned. Are you sure that Firefox can parse this data correctly? Firebug can also help with this.

Finally it isn't good practice to use synchronous mode. It will be better to modify your code to work asynchronously.

kgiannakakis
Are we even sure it's JSON coming back?
Nerdling
@Nerdling - well he has set dataType to json so hopefully!
redsquare
I doubt ie can parse the json and FF cannot, its normally the other way around, ie is alot more strict
redsquare
+1  A: 

Your best option is not to use asynch:false as this hangs up the browser and if for any reason the ajax call fails the user will have to close the browser window. Your best option is to pass a callback function into your existing API_LMSInitialize function which will be called on success of the ajax call. You will also have to re-work some of your calling code and move this into the callback function.

e.g

API_LMSInitialize( 'someParam', callbackFn);


function API_LMSInitialize(param, callback)
{

  $.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    url: "../../../GateWay/WebService.asmx/LMSInitialize",
    data: "{'courseid':'"+courseid+"','userid':'"+userid+"'}",
    dataType: "json",
    async: false,
    success: function(msg) { callbackFn(msg) },
    error: function(){ res="false"; }
  });

}

function callbackFn(msg){

     //do something with the returned data
}
redsquare
A: 

Configure the Web Service as Web Application in IIS if it's not already set.

John Kelemen