data is submitted in the form of form form in the foreground, and the front-end page can be rendered normally through res.render (ejs) in the background. The background code is as follows:
router.post("/classifyadd", (req, res) => {
let {classifyname} = req.body;
Classify.create({
name: classifyname
}).then(doc => {
responseData.msg = doc.name;
res.render("admin/frame", {
page: "successtip"
});
});
});
the problem is: when I submit data in the form of ajax, the background is written in the same way, but the front end cannot be rendered, and I see that the response header is really Content-Type: text/html; charset=utf-8
?
I know that after the front end gets the data, it can be stuffed into the page in the form of innerHTML, but I"m not sure this is the right way.
when using AJAX request, the backend cannot directly render (res.render) and can only return data. Is there any other way to operate DOM, after the frontend gets the data?
the same question link doesn"t have a good solution yet. Thank you!