Naz Kalidolda
Naz Kalidolda

Reputation: 21

Window.location is being canceled in ajax

I have problem with window.location. So I have ajax request as follows:

function login(){
	
	var u = document.getElementById("username").value;
	var p = document.getElementById("password").value;
	if(u == "" || p == ""){
		
	} else {
		var ajax = ajaxObj("POST", "ajaxResp.php");
        ajax.onreadystatechange = function() {
	        if(ajaxReturn(ajax) == true) {
	            if(ajax.responseText == "login_failed"){
					alert("fail");
				}
				 else {
					window.location = "user.php?u="+ajax.responseText;
				}
	        }
        }
        ajax.send("u="+u+"&p="+p);
	}
	return false;
}

where ajaxObj is decleared in other file. My ajaxResp.php send me back username to which i should redirect. But when I reach window.location, my request is cancelled. What can it mean?

Upvotes: 2

Views: 199

Answers (1)

epascarello
epascarello

Reputation: 207557

If the window.location line is being hit. you are not waiting for the Ajax call to be complete.

That means whatever the code is inside of the ajaxReturn is not checking for readyState to be complete.

Upvotes: 1

Related Questions