HI,
I am trying to xmlhttp object using ajax. In my first request I am getting the desired result. On the readystatechange I called a function whic process the response of the first request. According to the response of my first request, I fired the second httprequest. But the second httprequest always returns a status code 0. I got a message called request cancelled. Can anybody suggest what may be reason for the same.

Thanks
Pramod

try creating a different http object for each request. If you are still having problems, post your code.

try creating a different http object for each request. If you are still having problems, post your code.

Hi,
Thanks for your reply. Offcourse I am creating a different http object, But still getting some issue. Find the sample code here.

In callAgain function I am calling the same url with some additional http request header.
Here I am always getting status code 0.

/*
 * JavaScript file
 */
var proxyAuthID;
function init()
{
	var xhr;
	
    //var rssfeed = "http://65.182.161.95/GetRs.asp";
	var rssfeed = "http://phoneytunes.odp.mobile.pt.com:80/6779/v1/odplangconf";
    //var showDiv;
    //call the right constructor for the browser being used
    if (window.ActiveXObject) 
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    else 
        if (window.XMLHttpRequest) 
            xhr = new XMLHttpRequest();
        else 
            alert("AJAX request not supported");
    
    //prepare the xmlhttprequest object
    xhr.open("GET", rssfeed, true);
    xhr.setRequestHeader("Cache-Control", "no-cache");
    xhr.setRequestHeader("Pragma", "no-cache");
	xhr.setRequestHeader("User-Agent", "ptMobile/1.0 (ODP-PT;1.0)");
	xhr.setRequestHeader("X-Client-UUID", "B53333700-F84E-D09D-802A-448831341D8");
	xhr.setRequestHeader("X-pt-App-Id", "odp-pt");
	xhr.setRequestHeader("X-Request-Id", "762883947-H6sYUAEW");
    xhr.onreadystatechange = function(){
        if (xhr.readyState == 4) {
            if (xhr.status == 200) {
                if (xhr.responseText != null) {
                    //processRSS(xhr.responseXML, vid, hid);
					document.getElementById("RS1").innerHTML = xhr.responseText;
                }
                else {
                    alert("Failed to receive RSS file from the server - file not found.");
                    return false;
                }
            }
            else {
				if (xhr.status==401)
				{
					//xhr.getAllResponseHeaders();
					proxyAuthID = xhr.getResponseHeader("X-Proxy-Authenticate");
					proxyAuthID = proxyAuthID.substring(14,proxyAuthID.length-1);
					document.getElementById("RS1").innerHTML = xhr.getResponseHeader("X-Proxy-Authenticate");
					document.getElementById("RS2").innerHTML = "proxyAuthID: "+proxyAuthID;
                	alert("First Error code " + xhr.status + " received: " + xhr.statusText);
					xhr.abort();
					xhr=null;
					callAgain();
					//alert("Error code " + xhr.status + " received: " + xhr.statusText);					
				}
				//document.getElementById("RS1").innerHTML = xhr.responseText;

            }
        }
    }
    
    //send the request
    xhr.send(null);
}
var xhr1;
function callAgain()
{
	
	
    //var rssfeed = "http://65.182.161.95/GetRs.asp";
	var rssfeed = "http://phoneytunes.odp.mobile.yahoo.com:80/6779/v1/odplangconf";
	//var rssfeed = "http://phoneytunes.com/brew/aircelodp/aircelodp.asp";
    var secret = "ZgVkXhruD_TSa2pz.2TB.ZzZORgcotdG8Q.kYKb.Gow-";
	var User_Agent = "ptMobile/1.0 (ODP-PT;1.0)";
	//var URI = "/6779/odplangyss.js?intl=it";
	var URI = "/6779/v1/odplangconf";
	var HTTP_Method = "GET";
	var nonce = proxyAuthID;
	var yahooAppId = "odp-pt";
	var version="2";
	var H1,H2;
	var Response;
	var XProxyAuthorization;
	H1 = b64_md5(yahooAppId+":"+secret);
	H2 = y64(b64_md5(HTTP_Method+":"+URI));
	Response = y64(b64_md5(H1+":"+nonce+":"+H2));
	XProxyAuthorization = "Digest nonce="+"\""+nonce+"\""+" uri="+"\""+URI+"\""+" response="+"\""+Response+"\""+" version=\"2"+"\"";    
	//XProxyAuthorization = nonce+URI+Response;
	document.getElementById("RS3").innerHTML = "Response: "+Response;
	document.getElementById("RS4").innerHTML = "XProxyAuthorization: "+XProxyAuthorization;
	
    if (window.ActiveXObject) 
	{
		xhr1 = new ActiveXObject("Microsoft.XMLHTTP");
		alert("xmlhttp active object");
	}
    else 
        if (window.XMLHttpRequest) 
		{
			xhr1 = new XMLHttpRequest();
			alert("xmlhttp request");
		}
        else 
            alert("AJAX request not supported");
    
    //prepare the xmlhttprequest object
    xhr1.open("GET", rssfeed, true);
    xhr1.setRequestHeader("Cache-Control", "no-cache");
    xhr1.setRequestHeader("Pragma", "no-cache");
	xhr1.setRequestHeader("User-Agent", "ptMobile/1.0 (ODP-PT;1.0)");
	xhr1.setRequestHeader("X-Client-UUID", "B53333700-F84E-D09D-802A-448831341D8");
	xhr1.setRequestHeader("X-pt-App-Id", "odp-pt");
	xhr1.setRequestHeader("X-Request-Id", "762883947-H6sYUAEW");
	xhr1.setRequestHeader("X-Proxy-Authorization", XProxyAuthorization);
	//alert(XProxyAuthorization);
    xhr1.onreadystatechange = function ()
{
       //alert("Inside process requeset" + xhr1.readyState);
	    if (xhr1.readyState == 4) {
            if (xhr1.status == 200) {
                if (xhr1.responseText != null) {
                    //processRSS(xhr.responseXML, vid, hid);
					document.getElementById("RS1").innerHTML = "Hello Web tool kit" + xhr1.responseText;
                }
                else {
                    alert("Failed to receive RSS file from the server - file not found.");
                    return false;
                }
            }
            else {
					alert("Second Error code " + xhr1.status + " received::" + xhr1.statusText);					
					document.getElementById("RS5").innerHTML = "Error : " + xhr1.responseText;
            }
        }
    }//processrequest ();
    //send the request
    xhr1.send(null);
	//alert("second function");
}

it seems taht you are dealing with cached pages. Instead of: ...open("GET", rssfeed, true) use: ...open("GET", rssfeed+"?cb="+(new Date()).valueOf(), true)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.