0

HELP: where xmlHttp.status = 0

Please help me .
This problem abused me for months.

where I copy the URL into Firefox's location bar to visit website ,the website responses correctly,but when Using Ajax with same URL, the xml.status only is 0,just once. i Google lots of staff of which no one can solve it.

below is my code.
CODE
var consumer_Key ="dj0yJmk9WFNzYXluTW5IQW1vJmQ9WVdrOVdEVjRhbU5YTXpZbWNHbzlNVEV4TXpRd09EZ3lNQS0t
JnM9Y29uc3VtZXJzZWNyZXQmeD1kNw--";
var consumer_Secret ="53f395972cef451b2762145f7afe1dab27cfd8db";

var getReqToken =function(){
var url = "https://api.login.yahoo.com/oauth/v2/get_request_token";
url+="?oauth_nonce="+(new Date().getTime());
url+="&oauth_timestamp="+(Math.round(new Date().getTime()/1000)); //time zone
url+="&oauth_consumer_key="+consumer_Key;
url+="&oauth_signature_method=plaintext";
url+="&oauth_signature="+consumer_Secret+"%26";
url+="&oauth_version=1.0";
url+="&xoauth_lang_pref=en-us";
url+="&oauth_callback=http://www.the631.com/mymeme";

var query ={
q:url,
asyn:true,
type:"private",
data:"liang.wang;",
proxy:true,
cbFunction:function(reply){
alert(reply);
}
};
new Ajax(query);
}

//
var Ajax = function(options){
var xmlHttp;
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
var url = generateQuery(options);
var asyn = options.asyn==undefined?true:options.asyn;
xmlHttp.open("GET", url, asyn);
if(options.proxy){
xmlHttp.withCredentials =true;
xmlHttp.setRequestHeader("Proxy-Authorization","Basic bGlhbmcud2FuZzo4ZCFnV3hMMA==");
}

xmlHttp.onreadystatechange = function(){
if (xmlHttp.readyState == 4) {//completed
if(xmlHttp.status==200 || xmlHttp.status == 304){//success

var args;
if(!options.format || options.format.toLowerCase()=="text"){
args = xmlHttp.responseText;
}else{
if("json"==options.format.toLowerCase()){
args= JSON.decode( xmlHttp.responseText);
}else if("xml"==options.format.toLowerCase()){
args = xmlHttp.responseXML;
}
}
var callback = options.cbFunction;
if(typeof(callback)=="function"){
callback(args);
}else{
window[callback](args);
}
}
}
};
xmlHttp.send(options.data==undefined?"":options.data);
//firefox does't work well when asyn=false;
if(!asyn){
if (xmlHttp.readyState == 4) {//completed
if(xmlHttp.status==200 || xmlHttp.status == 304){//success

var args;
var type = options.format.toLowerCase();
if("json"== type){
args= JSON.decode(xmlHttp.responseText);
}else if("xml"==type){
args =xmlHttp.responseXML;
}else{
args= xmlHttp.responseText;
}
var callback = options.cbFunction;
if(typeof(callback)=="function"){
callback(args);
}else{
window[callback](args);
}
}
}
}
}

by
0 Replies

Recent Posts

in YQL