/    Sign up×
Community /Pin to ProfileBookmark

Weird problem with AJAX

var auth;
function onAccept()
{
var d = document;
var userSetting = new Object;
userSetting[‘password’] = d.getElementById(‘password’).value;
userSetting[‘username’] = d.getElementById(‘username’).value;
request();
return true;
}

function Contents(httpRequest)
{
try
{
if(httpRequest.readyState == 4)
{
if(httpRequest.status == 200)
{
alert(“I am here”); setPreference(‘response’,httpRequest.responseText);
}
else
alert(httpRequest.status);
}

} catch(ex){}

}

function request()
{
var url = “https://www.google.com/accounts/ClientLogin“;
var params = “accountType=HOSTED_OR_GOOGLE&Email=[email protected]&Passwd=password&service=cl&source=Gulp-CalGulp-1.05″;
var httpRequest = null;

if(window.XMLHttpRequest)
{
httpRequest= new XMLHttpRequest();
if(httpRequest.overrideMimeType)
httpRequest.overrideMimeType(‘text/xml’);
}
else if(window.ActiveXObject)
{
try
{
httpRequest = new ActiveXObject(“Msxml2.XMLHTTP”);
}catch(e){ try{ httpRequest = new ActiveXObject(“Microsoft.XMLHTTP”);}
catch(e){}}
}
if(!httpRequest){alert(“giving up!”);return false;}

try{

httpRequest.open(“POST”, url ,true );
httpRequest.setRequestHeader(“Content-Type”, “application/x-www-form-urlencoded”);
httpRequest.setRequestHeader(“Cache-Control”, “no-cache”);
httpRequest.onreadystatechange =function(){ Contents(httpRequest);};
httpRequest.send(params);}catch(e){alert(“I got error in sending the message”);}

}

function getPreference(whichpref)
{
var pref = Components.classes[‘@mozilla.org/preferences-service;1’].
getService(Components.interfaces.nsIPrefService).
getBranch(‘sample.’);
pref.QueryInterface(Components.interfaces.nsIPrefBranch2);
var stringtext = pref.getCharPref(whichpref);
alert(“response is n” + stringtext);
pref.setCharPref(whichpref,”);
}
function setPreference(whichpref, text)
{
var pref = Components.classes[‘@mozilla.org/preferences-service;1’].
getService(Components.interfaces.nsIPrefService).
getBranch(‘sample.’);
pref.QueryInterface(Components.interfaces.nsIPrefBranch2);
pref.setCharPref(whichpref,text);
}

Each time I run above code it is giving the error the “contents is not defined”(contents is the call back function).I am not getting my error in above program .Please help me out

Thank You

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @pawan_sin99 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...