0

I have written a javascript function that calls a web service to save data. When the web service is called an alert pops up saying the server method saveUpdateCodes failed, and it gives no other information. The thing is the web service executes and throws no errors (I've stepped though it). Also, the alerts in the catch in the javascript code never happen. Does anyone no how this can happen? Could it be the browser, my code...? For testing, I am using Firefox w/ the firebug plugin. The javascript code is below, if you need more information, please ask. Thanks.

This is the call to the web servcie

try
    {
        //debugger;
        //call the service to do the save
        codeList.editcodes.saveUpdateCodes(sUsrList, sCharge, sCodes, sId, afterSave, OnsaveUpdateCodesFailure);
        
        //close the progress panel
        hideProgress(); 
    
    }
    catch(e)
    {
        //debugger;
        alert(e.description);
        alert(e.number);
    }

These are my onSuccess & onFailure functions

function afterSave(result)
{
    //the web service returns an empty string on success & a err message onFailure
    //if the save was successfull, go to the previous page
    if (result == '')
        history.go(-1); 
    else
    {
        alert('There was an error saving the data. Please try again');
        //may need to go back here
    }
    hideProgress();   
}

function OnsaveUpdateCodesFailure( result )
{
    alert( result.get_message() );
    //history.go(-1);
    //debugger;
}
3
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by hielo
0

yes , its still not clear from the post that what exactly your script is trying to achieve.explain that too and this is not the complete code i guess..

0

yes , its still not clear from the post that what exactly your script is trying to achieve.explain that too and this is not the complete code i guess..

Sorry for any confusion, I'll try to be a little more clear and I've also learned a few things about what is happening. The code that you see is simply calling a web service and passing params that are saved to a database by the webservice. You are right, it isn't all the code. The rest of the code just gets data from the form and stores in those vars that are being passed.

What I have learned studying the situation is that javascript is not waiting for a response from the web service. It continues on and determines that result is undefined. While that is happening the webservice goes ahead and successfully saves the data then returns success. The problem is, javascript had already moved on as if what was returned was undefined. (I hope I'm saying this in a way that makes sense).

I guess now my question is, how do I make javascript wait for an answer from the webservice? Any ideas? Do you think that I need to post a new question?

Thanks.

0

Where is your implementation for saveUpdateCodes? My guess is that your bug is in that function.

0

Hi Hielo, thanks for the interest and thanks to everyone that helped. I found a workaround. The problem wasn't the web service but that javascript wasn't waiting for a response from the web service. What I did to fix this was to set the return type of the web service to void instead of string and now it runs successfully every time.

I think that having success or error returned from the web service would be the best coding practice but this will let me proceed with the project and get back on schedule.

Thanks,

0

that javascript wasn't waiting for a response from the web service

I know, that's why I wanted to see your js implementation of saveUpdateCodes(). My guess is you are sending an asynchronous request be do not have a callback function to determine the completion of the request.

Alternatively you can execute a synchronous request.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.