Показать сообщение отдельно
  #1 (permalink)  
Старый 18.01.2015, 02:27
Аспирант
Отправить личное сообщение для kilohertz_. Посмотреть профиль Найти все сообщения от kilohertz_.
 
Регистрация: 07.12.2014
Сообщений: 31

Объект ajax и приостановка функции
Есть объект, который занимается ajax запросами. Как сделать, что бы функция, из которой был вызван объект ajax как бы приостанавливалась и продолжала выполняться когда придет ответ с сервера?

Объект ajax:
function ajax() { //json object
	this.xhr;
	this.result = {"result":"empty"};
	
	this.send = function(addr, string, method='POST', async=true){
		this.xhr = new XMLHttpRequest();
		this.xhr.open(method,addr,async);
		if(method == 'POST') this.xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		this.xhr.send(string);
		this.xhr.onreadystatechange = this.get;
	}
	
	this.get = function(){
		if(this.xhr.readyState == 4) {
			this.result = JSON.parse(this.xhr.responseText);
			if(this.result.status == 'complete') {return this.result}
			if(this.result.status == 'error') {
				return showMsg(1,this.result.error);
			}
		}
	}
	
	this.ready = function() {}
}


Вызывается отсюда:
function listRegions(node, type, filter=null) {
	var xhr = new ajax();
	
	xhr.send('/ajax/regions.php',string);
	
}
Ответить с цитированием