i have a vue cli project, and i am trying to make an ajax call in my application, and it is working if i go on the localhost:7999, but i want it to work on the same page as my application, which is on localhost:8080. i have heard of Axios but maybe if there is a way without using Axios, i am hoping that i could find it here.
vue.config.js
global.changement = "Johnny Depp";
var express = require('express')
var session = require('express-session')
var app = express();
var bodyParser = require('body-parser');
var userStoredInMemory = "LEBROONNN JAMES";
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.get('/', function (req, res) {
res.sendFile(__dirname + '/public/index.html');
});
app.get('/api/user', function (req, res) {
res.json(changement);
});
app.post('/api/user', function (req, res) {
// userStoredInMemory = req.body;
// userStoredInMemory = "oui";
res.send('User was already stored from express.');
});
app.listen(7999, function () {
console.log('server up and running at 8080 port');
});
index.html
function lebron() {
$(document).ready(function () {
$.ajax({
type: 'GET',
url: 'http://localhost:7999/api/user'
})
.done(function (data) {
alert(JSON.stringify(data));
localStorage.setItem('name',JSON.stringify(data));
});
});
}
setInterval(lebron, 1000);
We're sorry but it doesn't work properly without JavaScript enabled. Please enable it to continue.
there is not output, no alert is done.