Guest User

Untitled

a guest
Jul 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. function A() {
  2. this.b = 13;
  3. function finish(context,response) {
  4. context.b = response;
  5. }
  6. ajax(finish,this);
  7. }
  8.  
  9. A.prototype = {
  10. constructor: A
  11. }
  12.  
  13. function ajax(callback,context) {
  14. var http = new XMLHttpRequest();
  15. var url = "phppage.php";
  16. http.open("GET", url, true);
  17. http.onreadystatechange = recall;
  18. function recall() {
  19. alert('a');
  20. if(http.readyState == 4 && http.status == 200) {
  21. callback(context,http.responseText);
  22. }
  23. }
  24. http.send(null);
  25. }
  26.  
  27. var d = new A();
  28. alert(d.b);
  29.  
  30. function A() {
  31. this.b = 13;
  32. //this is how you should be storing contexts
  33. var that = this;
  34. function finish(response) {
  35. that.b = response;
  36. }
  37. ajax(finish);
  38. }
  39.  
  40. function ajax(callback) {
  41. var http = new XMLHttpRequest();
  42. var url = "phppage.php";
  43. http.open("GET", url, true);
  44. http.onreadystatechange = function() {
  45. alert('a');
  46. if(http.readyState == 4 && http.status == 200) {
  47. callback(http.responseText);
  48. }
  49. }
  50. http.send(null);
  51. }
  52.  
  53. http.open("GET", url, false);
Add Comment
Please, Sign In to add comment