Answer the question
In order to leave comments, you need to log in
How to fetch data and display everything via ajax?
I'm trying to make a request via ajax, but for some reason I don't see a specific output in the console.
In the router
const Router = require('koa-router'),
Order = require('../models/order'),
router = new Router();
router.get('/order/:id', async(ctx) => {
let order = Order.find({orderId: ctx.params.id}).exec((err, order) => {
if (err) return err;
return order;
});
console.log(ctx.params.id);
})
let key = lineTr.data('key');
console.log(key);
$.get({
url: '/order/'+key,
}).done((order) => console.log(order));
Answer the question
In order to leave comments, you need to log in
Issue resolved, should have done this
router.get('/order/:id', async(ctx) => {
await Order.findOne({orderId: ctx.params.id}).exec((err, id) => {
if (err) return err;
ctx.body = id;
});
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question