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

проблема с readyState
Ошибка: Uncaught TypeError: Cannot read property 'readyState' of undefined в строчке
if(this.xhr.readyState == 4) {


function ajax(callback) { //json object
	this.xhr;
	this.result = {"result":"empty"};
	
	this.send = function(addr, string, method, async){
		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') {
				if(!(callback === null)) {callback}
			}
			if(this.result.status == 'error') {
				return showMsg(1,this.result.error);
			}
		}
	}
	
}
Ответить с цитированием