Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function A() {
- this.b = 13;
- function finish(context,response) {
- context.b = response;
- }
- ajax(finish,this);
- }
- A.prototype = {
- constructor: A
- }
- function ajax(callback,context) {
- var http = new XMLHttpRequest();
- var url = "phppage.php";
- http.open("GET", url, true);
- http.onreadystatechange = recall;
- function recall() {
- alert('a');
- if(http.readyState == 4 && http.status == 200) {
- callback(context,http.responseText);
- }
- }
- http.send(null);
- }
- var d = new A();
- alert(d.b);
- function A() {
- this.b = 13;
- //this is how you should be storing contexts
- var that = this;
- function finish(response) {
- that.b = response;
- }
- ajax(finish);
- }
- function ajax(callback) {
- var http = new XMLHttpRequest();
- var url = "phppage.php";
- http.open("GET", url, true);
- http.onreadystatechange = function() {
- alert('a');
- if(http.readyState == 4 && http.status == 200) {
- callback(http.responseText);
- }
- }
- http.send(null);
- }
- http.open("GET", url, false);
Add Comment
Please, Sign In to add comment