I'm sending HTTP requests with jQuery's AJAX and it doesn't return a value.
I created a Http object that handles the request and a request() method that is supposed to return the gotten from the request.
class Http
constructor(url,type = 'GET') {
this.url = url,
this.type = type;
}
request() {
let response = '';
$.ajax({
'url': this.url,
'type': this.type,
dataType: 'json',
success: (data) => {
response = data
// console.log(data) - **works**
// return data - **doesn't work**
},
error: (error) => {
response = data;
}
});
return response;}