0

I have the following code:

AJAX:

function GetLoggedInUserName() {
    var username = null;
    $.ajax({
        url: 'Login.aspx/GetLoggedInUserName',
        type: 'POST',
        contentType: 'application/json; charset=utf-8',
        async: false,
        dataType: "json",
        data: '{ }',
        success: function(Result) {
            if (Result != "") {
                var ClientResponse = JSON.parse(Result.d);
                alert("res: " + ClientResponse.Success);
                alert("data:" + ClientResponse.Data);
                if (ClientResponse.Success) {
                    username = ClientResponse.Data;
                }

                else {
                    showDialog('indicator', {
                        message: ClientResponse.Message,
                        type: 'error'
                    }, false);
                }
            }
        },
        error: function(xhr, textStatus, errorThrown) {
            showDialog('indicator', {
                message: 'An error occured in GetLoggedInUserName',
                type: 'error'
            }, false);
        }
    });

return username;

}

Use:

        var loggedInUser = GetLoggedInUserName();

        alert(loggedInUser);

when I run this code on PC, everything is working fine. when I ran this code on IPAD (safari/chrome) then I get "null" in the alert, and then I get the alerts I have inside the ajax call:

                alert("res: " + ClientResponse.Success);
                alert("data:" + ClientResponse.Data);

So I suppose that async: false doesn't really works on IPAD. Is it true? Is there any way to use synchronous ajax calls on IPAD?

Inbal
  • 909
  • 2
  • 28
  • 46
  • 1
    Why do you need synchronous calls? That's almost never the answer. – Matt Ball Sep 29 '13 at 16:18
  • I want to pass the logged in user name to a jquery template as a parameter, So I need it to be synchronous in order to make sure it is not null. Do you have other solution how to do it? – Inbal Sep 29 '13 at 18:41
  • Render the template in the success callback, as per http://stackoverflow.com/q/14220321/139010. – Matt Ball Sep 29 '13 at 23:38

0 Answers0