Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error #35

Closed
mikaspell opened this issue Jun 24, 2016 · 13 comments
Closed

Error #35

mikaspell opened this issue Jun 24, 2016 · 13 comments
Labels

Comments

@mikaspell
Copy link

Hey. I caught this error
Unhandled rejection ReferenceError: XMLHttpRequest is not defined

in my controller i'm add your module like that:
ajax = require('@fdaciuk/ajax')

then
const aQuery = ajax({ baseUrl: 'https://some-site/api/'})

and then request
aQuery.post('/user/nop', { headers: { 'content-type': null }, data: { password: res.dataValues.password, username: res.dataValues.username } });

After I got the error I added:
XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest, xhr = new XMLHttpRequest()

and it did not help. Are there any ideas about this?

@fdaciuk
Copy link
Owner

fdaciuk commented Jun 24, 2016

Hey @mikaspell! headers should be passed on ajax method, and data should be just an object. Refactoring your code, it will look like this:

const ajax = require('@fdaciuk/ajax')

// configuration for your request
const aQuery = ajax({ 
  baseUrl: 'https://some-site/api/',
  headers: { 'content-type': null }
})

// now, make the request
aQuery.post('/user/nop', { 
  password: res.dataValues.password, 
  username: res.dataValues.username 
})

Let me know if it helped you =)

@mikaspell
Copy link
Author

@fdaciuk unfortunately it did not help

@fdaciuk
Copy link
Owner

fdaciuk commented Jun 24, 2016

Are you trying this locally?

@mikaspell
Copy link
Author

yes

@fdaciuk
Copy link
Owner

fdaciuk commented Jun 24, 2016

Which browser are you using?

@mikaspell
Copy link
Author

trace:
Unhandled rejection ReferenceError: XMLHttpRequest is not defined at n (/Users/MikaSpell/Documents/Git/ihstr/node_modules/@fdaciuk/ajax/dist/ajax.min.js:9:570) at Object.r.(anonymous function) [as post] (/Users/MikaSpell/Documents/Git/ihstr/node_modules/@fdaciuk/ajax/dist/ajax.min.js:9:378) at db.define.hooks.afterValidate (/Users/MikaSpell/Documents/Git/ihstr/app/models/User.js:50:14) at /Users/MikaSpell/Documents/Git/ihstr/node_modules/sequelize/lib/hooks.js:141:19 at tryCatcher (/Users/MikaSpell/Documents/Git/ihstr/node_modules/bluebird/js/release/util.js:16:23) at Object.gotValue (/Users/MikaSpell/Documents/Git/ihstr/node_modules/bluebird/js/release/reduce.js:145:18) at Object.gotAccum (/Users/MikaSpell/Documents/Git/ihstr/node_modules/bluebird/js/release/reduce.js:134:25) at Object.tryCatcher (/Users/MikaSpell/Documents/Git/ihstr/node_modules/bluebird/js/release/util.js:16:23) at Promise._settlePromiseFromHandler (/Users/MikaSpell/Documents/Git/ihstr/node_modules/bluebird/js/release/promise.js:502:31) at Promise._settlePromise (/Users/MikaSpell/Documents/Git/ihstr/node_modules/bluebird/js/release/promise.js:559:18) at Promise._settlePromiseCtx (/Users/MikaSpell/Documents/Git/ihstr/node_modules/bluebird/js/release/promise.js:596:10) at Async._drainQueue (/Users/MikaSpell/Documents/Git/ihstr/node_modules/bluebird/js/release/async.js:143:12) at Async._drainQueues (/Users/MikaSpell/Documents/Git/ihstr/node_modules/bluebird/js/release/async.js:148:10) at Immediate.Async.drainQueues [as _onImmediate] (/Users/MikaSpell/Documents/Git/ihstr/node_modules/bluebird/js/release/async.js:17:14) at processImmediate [as _immediateCallback] (timers.js:383:17)

i use Chrome

@mikaspell
Copy link
Author

here the problem is not likely to form in the request, and in that it requests a module that is mounted

@fdaciuk
Copy link
Owner

fdaciuk commented Jun 24, 2016

Yes.. really weird. Can you show me all your code? Is it on GitHub?

@mikaspell
Copy link
Author

mikaspell commented Jun 25, 2016

@fdaciuk yeap

@luanmuniz
Copy link

@mikaspell The way i can see here you are trying to use the module inside Node.js environment not the browser. In that case you should use something like got or request

@fdaciuk
Copy link
Owner

fdaciuk commented Jun 25, 2016

@mikaspell , ajax library does not work on server side. Please, use some library recommended by @luanmuniz above =)

@fdaciuk fdaciuk closed this as completed Jun 25, 2016
@mikaspell
Copy link
Author

@luanmuniz thank you! and @fdaciuk sorry for distracts you

@fdaciuk
Copy link
Owner

fdaciuk commented Jun 26, 2016

No problem @mikaspell =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants