In the below piece of code I am not getting the locale in the second alert 
if `value==null`
I assign its locale value. but do not get it at the end.  
function getLocale(id) {
    var locale="";
    var value = localStorage.getItem(id);
    if (value == null) {
        $.ajax({
            type: "POST",
            url: "myUrl",
            data: {"new" : id},
            success : function(data) {
                data = JSON.parse(data)
                var id = data[0]["id"];
                delete data[0]["id"];
                localStorage.setItem(id, JSON.stringify(data[0]));
                locale=JSON.stringify(data[0]);
                alert(locale);//corrects value
            }// end success
        });
    }else{
        locale= localStorage.getItem(id);
    }
    alert(locale+"locale");//not have the value
    return locale;
}
 
     
    