views:

70

answers:

3

I've made a JQuery function that makes a call to a web service, the web service returns an int but somewhere between the web service returning its value and the JQuery picking it up the data is getting lost. below is my Jquery Function:

//Make a call to a web service to get the latest number of comments for this item
    WebDesign.wfGetNumberOfCommentsForWebDesignItem(vintCurrentItemID,fGetNumberOfCommentsResult);

    function fGetNumberOfCommentsResult(GetNumberOfCommentsResult){
       //If the number of comments returned is not zero update the the number of comments
       if (GetNumberOfCommentsResult != -1 && GetNumberOfCommentsResult != null)
       {
          vspanCommentsNumber.html(GetNumberOfCommentsResult);
       }
       else
       {
          vspanCommentsNumber.html("Unknown");
       }
    }

The variable GetNumberOfCommentsResult is null, not every time but I'd say about 10% of the time. I've recorded the data that the web service returns to the JavaScript and it's not null, it's valid data, so I'm at a loss as to how the JavaScript variable is set as null. Any ideas?

+1  A: 

Can you confirm that you are running this in a callback, when the call to the webservice is guaranteed done, and not some timed method using setTimeout ? in the second case, a race condition could explain the variable results that you are getting.

Olivvv
A: 

use fiddler or something similar to monitor http requests and actually grab the response when it is null, there has to be something different about it.

Chris Westbrook
A: 

Using FireBug (add-on for Firefox), on the Console tab you can see what data is being returned from the web service call, as well as what data is being passed.

First verify the data being moved back and forth. This is the easiest way to find a truly reproducible case.

Also, it would be helpful to see how you are calling the web service on the JavaScript side.

Chris Brandsma