I am trying to populate the database with some fake data using https://randomuser.me/api/
This is done in file “/server/fixtures.js” as you can see in the code below.
When I run meteor I get this message in command prompt on windows: TypeError: ajax is not a function
The same code if run on the client works perfectly fine with no errors and success function called.
This is done in file “/client/main.js” within a Meteor.startup function without importing $.
Just to be sure, I also tried those import syntaxes below and I still get the same error
import { $ } from ‘meteor/jquery’;
or also
import jQuery from ‘meteor/jquery’;
or even both
I also tried installing jQuery from npm. I still get the same error.
Anyone had this problem ?
// code in file "/server/fixtures.js" renders TypeError: ajax is not a function
import $ from 'meteor/jquery';
Meteor.startup ( () => {
$.ajax({
url: 'https://randomuser.me/api/?results=3',
dataType: 'json',
success: function(data) {
console.log(data);
}
});
// code in file "/client/main.js" works fine with no errors
Meteor.startup ( () => {
$.ajax({
url: 'https://randomuser.me/api/?results=3',
dataType: 'json',
success: function(data) {
console.log(data);
}
});