I would like to know how to return both html and json as response in ajax call success function

how to Render both html and json data as response from nodejs to ajax(client) I have a code below both client and server.

//ajax call
  var self= this
          url: '/en',
          method: 'get',
          data: {
            source: "SG",
            target: "IN",
            amt: amt
          success: function (data) {
            $('body').html(data.ejs) // html file
            self.updateValue(data.taramt);// update json data
    this.shadowRoot.getElementById("ramount").value = d;

var express = require('express');
var app = express();
app.use(bodyParser.urlencoded({ extended: true}));

var languageRouter = require('./routes/language');
app.use('/en', languageRouter);

// language.js
var express = require('express');
var router = express.Router();
var util = require('../util.js');

router.get('/', function (req, res) {
    util.getRateByBiz4x(req.query).then(val => {
       res.render( "index.ejs"  ,{taramt: val });
module.exports = router;

0 Answers