/    Sign up×
Community /Pin to ProfileBookmark

this.t = setTimeout("objekt.ajaxHentEndringer", 1000);???

hi. i have a problem and was hoping someone could help.
sorry for my english and all the norwegian words in my code

i have a project where i have to do an ajax call for som json.
i have to print out the response and it works the first time, but
when it is supposed to check a second time the context has
changed and this isnt this anymore.

anyone know how i can fix it without using more global variables or
functions??

[CODE]
function medlemslisteobjekt() {
this.medlemsliste = new Array();
this.loggId = -1;
this.t;
this.xmlHttp;
}

var objekt = new medlemslisteobjekt();

medlemslisteobjekt.prototype.stopTimer = function() {
//alert(“stoptimer”);
clearTimeout(this.t);
};

medlemslisteobjekt.prototype.startTimer = function() {
//alert(“starttimer”);
this.t = setTimeout(“objekt.ajaxHentEndringer”, 1000);
};

medlemslisteobjekt.prototype.handleServerResponse = function() {
//alert(“handleserverresp”);
if (this.xmlHttp&&this.xmlHttp.readyState == 4) {
if (this.xmlHttp.status == 200) {
this.startTimer();
var response = JSON.parse(this.xmlHttp.responseText.split(“,”));
[/CODE]

i know i havnt given you alot of code but the whole thing is 200 lines
thanks for any response

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@norbaggaauthorNov 12.2011 — need this 2?

[CODE]medlemslisteobjekt.prototype.ajaxHentEndringer = function() {
//alert("ajaxhentendringer");
//this.stopTimer();
this.xmlHttp = this.hentXMLHTTP();
if (this.xmlHttp) {
this.xmlHttp.open("GET", "EndringerHent?loggId=" + this.loggId, true);
this.xmlHttp.onreadystatechange = function(){
objekt.handleServerResponse();
};
/*this.xmlHttp.onload = function(){
objekt.handleServerResponse();
};*/

//this.handleServerResponse(xmlHttp);
this.xmlHttp.send(null);
}
};[/CODE]
×

Success!

Help @norbagga 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.17,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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