Problems with the mat-part ... Just described something similar. In general, in order for your code to work:
function get_settings(ans){ var request = getXmlHttp(); // глобальная переменная var answer; request.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { onRequestComlete(request.responseText); } } request.open("POST", "ajax.php", true); request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); request.send("act=get_set&ans="+ans); } function onRequestComplete(data) { // обработчик ответа сервера alert(data); // сдесь пишите код который должен отработать после получения // данных от сервера }
If you need something, the script would "fall asleep" until there is no response from the server, use a synchronous request, or something from the one I described here
Now I will explain why you wrote something like this: onreadystatechange this event and your code
if (this.readyState == 4 && this.status == 200) { return request.responseText; }
It is executed when this event occurs, moreover, also under additional conditions, in general, the model of asynchronous ajax request is event oriented, i.e. you cannot write linear code, you must describe the code in chains of events, or, as I wrote, use synchronous ajax (it was invented in order to write linear code)
I wrote - for this, use a synchronous (blocking) ajax request, at the time of its execution, the page seems to freeze (and if at this moment the IE7 connection is not answered), but then you can write what you want.
To make using synchronous ajax request:
function get_settings(ans){ var request = getXmlHttp(); // глобальная переменная var answer; windows.status("ожидание ответа сервера..."); request.open("POST", "ajax.php", false); request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); request.send("act=get_set&ans="+ans); return request.responseText; } var settings = get_settings(""); alert(settings)