>  var tr;
>                 function updateNummbers(typ) {
>                     var ret = "";
>
>                     $.ajax({ type: "POST",
>                         url: "DFWebService.asmx/getNummbers",
>                         dataType: "text",
>                         data: "typ=" + typ,
>                         processData: false,
>                         error: function(XMLHttpRequest, textStatus,
> errorThrown) { ajaxError(XMLHttpRequest, textStatus, errorThrown); },
>                         success: function(xml) {
>                             ret = $(xml.replace(/&lt;/g, "<").replace(/&gt;/
> g, ">")).find('anzahl').text();
>                             tr = ret;
>                             alert(tr); // OK
>                             alert(ret); // OK
>                         }
>                     });
>                 alert(ret);      // VALUE ""
>                 }
>                 updateNummbers('new');
>                alert(tr); // NO VALUE
>
> it is placed in
>
>         $(document).ready(
>             function() {
>
> I don't know why the value of updated variable tr outside function
> updateNummbers don't exists. In alert inside this function value is
> ok, but then I put alert after the function values are not correct.
> The same situation is for variable ret.
>
> Can anyone explain that to me?


Remember, the 'A' in ajax stands for 'asynchronous'.  Your tr and ret
variables are not set when you call $.ajax.  They are set whenever the
server response is received.

Reply via email to