I am trying to make a request to an external resource in a webpack module (my_request.js
), but when I call the method from my main.js
script, it returns undefined. Anyone experienced this problem or have any thoughts?
// my_request.js
define(['jquery'], function($) {
var makeRequest = function() {
$.get('http://api.example.com', function(data) {
return data;
});
};
});
// main.js
require(['./js/my_request'], function(request) {
var r = request.makeRequest();
console.log(r); // returns undefined
});