nicklandgrebe / active-resource.js

ActiveResource.js - API resource relational mapping in JavaScript
https://active-resource.js.org
MIT License
133 stars 20 forks source link

jQuery.ajax is not a function #8

Closed sellittf closed 5 years ago

sellittf commented 7 years ago

Hi,

I've experience with Rails and I'm now just trying out nodejs. Thanks for your port of ActiveResource as node module.

For sure I'm doing something wrong that should be very simple, in fact even if you're including jquery as dependency, I got the error "jQuery.ajax is not a function".

This is my very simple code:

index.js

require('coffee-script/register');
require('./customer');

customer.coffee

ActiveResource = require("activeresource")

MyLibrary = ActiveResource.createResourceLibrary(
  'https://example.com/api/v1/'
)

class MyLibrary::Customer extends MyLibrary.Base
  this.className = 'Customer'
  this.queryName = 'customers'

customers = MyLibrary::Customer.where(name: 'Alice').all();

running $ node index.js the error message is TypeError: jQuery.ajax is not a function

Thanks!

nicklandgrebe commented 7 years ago

Thanks for the submission! I just wanted to update you so you weren't left hanging.

I originally designed ActiveResource for the browser, I regrettably didn't even test it in Node. I just slapped a UMD wrapper on it and called it a day. As such, I never caught the fact that jQuery.ajax is not a thing in Node, because Node does not have XMLHttpRequest

I'm working on remedying this issue, but its proving a bit difficult and I ran out of free time today to make it happen. I won't be able to tackle this problem until next weekend.

I hope that does not inconvenience you too much.

nicklandgrebe commented 5 years ago

https://github.com/nicklandgrebe/active-resource.js/pull/30