N
noon
var pi_XHR = {
init: function init(title, d) {
pi_Logger.log('The item title is "' + title + '"');
title = title.replace(/\s+/g, '+');
this.request('http://imdb.com/find?s=tt&q='+title, this.decide,
d);
},
request: function request(url, callback, d) {
pi_Logger.log('Requesting ' + url + ' with a callback of "' +
callback.name + '()"');
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.onreadystatechange = this.rs(xhr, url, callback, d);
xhr.setRequestHeader('Referer', 'http://google.com');
xhr.send(null);
},
rs: function rs(xhr, url, callback, d) {
return function() {
if (xhr.readyState != 4) return;
if (xhr.status != 200) { pi_Logger.log('HTTP '+xhr.status);
return; }
with (xhr.responseText) {
if (indexOf('<title>IMDb Title') != -1) {
pi_Logger.log('We got IMDB search results');
var s = indexOf('<br>1.</td>');
if (s == -1) {
pi_Logger.log('There werent any results on this page');
return;
}
var link = substring(s, indexOf('</a>', s));
link = link.substring(link.indexOf('<a href="')+9,
link.lastIndexOf('">'));
window.setTimeout(this.request, 1, link, callback, d);
pi_Logger.log('Extracted ' + link);
}
else if (indexOf('A message from today') != -1) { // RT ad page
pi_Logger.log('RT ad page...');
} else {
pi_Logger.log('We think we have good HTML and are sending it to
"' + callback.name + '()"');
callback(xhr.responseText, d);
}
}
}
},
decide: function decide(html, d) {
pi_Logger.log("decide::Type of 'this' = "+typeof(this));
pi_Logger.log("decide::Name of 'this' = "+this.name);
pi_Logger.log("decide::Type of 'this.request' = "
+typeof(this.request));
}
};
Everything is good and fine until I get to my decide function. For
whatever reason this.request doesn't exist. Console shows me that the
type of this is object, name of this is blank, and
typeof(this.request) is undefined. If I replace this with pi_XHR it
works fine again. But in my other functions I can use this...
Critiquing, *cough* making fun of *cough*, my weak code skills is
encouraged
init: function init(title, d) {
pi_Logger.log('The item title is "' + title + '"');
title = title.replace(/\s+/g, '+');
this.request('http://imdb.com/find?s=tt&q='+title, this.decide,
d);
},
request: function request(url, callback, d) {
pi_Logger.log('Requesting ' + url + ' with a callback of "' +
callback.name + '()"');
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.onreadystatechange = this.rs(xhr, url, callback, d);
xhr.setRequestHeader('Referer', 'http://google.com');
xhr.send(null);
},
rs: function rs(xhr, url, callback, d) {
return function() {
if (xhr.readyState != 4) return;
if (xhr.status != 200) { pi_Logger.log('HTTP '+xhr.status);
return; }
with (xhr.responseText) {
if (indexOf('<title>IMDb Title') != -1) {
pi_Logger.log('We got IMDB search results');
var s = indexOf('<br>1.</td>');
if (s == -1) {
pi_Logger.log('There werent any results on this page');
return;
}
var link = substring(s, indexOf('</a>', s));
link = link.substring(link.indexOf('<a href="')+9,
link.lastIndexOf('">'));
window.setTimeout(this.request, 1, link, callback, d);
pi_Logger.log('Extracted ' + link);
}
else if (indexOf('A message from today') != -1) { // RT ad page
pi_Logger.log('RT ad page...');
} else {
pi_Logger.log('We think we have good HTML and are sending it to
"' + callback.name + '()"');
callback(xhr.responseText, d);
}
}
}
},
decide: function decide(html, d) {
pi_Logger.log("decide::Type of 'this' = "+typeof(this));
pi_Logger.log("decide::Name of 'this' = "+this.name);
pi_Logger.log("decide::Type of 'this.request' = "
+typeof(this.request));
}
};
Everything is good and fine until I get to my decide function. For
whatever reason this.request doesn't exist. Console shows me that the
type of this is object, name of this is blank, and
typeof(this.request) is undefined. If I replace this with pi_XHR it
works fine again. But in my other functions I can use this...
Critiquing, *cough* making fun of *cough*, my weak code skills is
encouraged