javascript - Ajax error in module: the object's state must be OPENED -
i trying add ajax method module without using jquery first time. keep getting following error on method .jax()
says uncaught invalidstateerror: failed execute 'send' on 'xmlhttprequest': object's state must opened.
i not sure how resolve that. here's module , simple html.
var test = (function (el) { function innertest () { this.el = el; //capital letters indicate constant should not change. this.para = 'p' this.init(); }; innertest.prototype.init = function () { .createchildren() .runit() .jax(); }; innertest.prototype.createchildren = function () { this.para = this.el.queryselectorall(this.para); return this; }; innertest.prototype.runit = function () { var len = this.para.length; (var = 0, item; item = this.para[i]; i++) { //test if browser supports classlist method else use classname add class. if (item.classlist) { item.classlist.add(item.textcontent) } else { item.classname += ' ' + item.textcontent } console.log( item ); console.log( item.classlist ); } return this; }; innertest.prototype.jax = function () { var self; var request = new xmlhttprequest(); request.open = ('get', 'https://api.github.com/users/xxxxxxxxx', true); request.send(); request.onload = function () { data = json.parse(this.reponse); console.log( data ); }; return this; }; return innertest; }( document.queryselector('.box') )); (function () { new test(); }());
here's html:
<div class="box"> <p>one</p> <p>two</p> <p>three</p> </div>
open method, not property
request.open = ('get', 'https://api.github.com/users/xxxxxxxxx', true); ^^^
should be
request.open('get', 'https://api.github.com/users/xxxxxxxxx', true); ^^^
Comments
Post a Comment