<html> <head><title>504 Gateway Time-out</title></head> <body> <center><h1>504 Gateway Time-out</h1></center> <hr><center>nginx</center> </body> </html>

1 ES6 template string does not work in $.ajax
2 normal code:

let title = 1;
let info = 2;
${title}  //1
${info}   //2

not shown if you put it in $.ajax, code:

    $.ajax({
    type: "get",
    url: "xxxxx.json",
    dataType: "json",
    success: function(x) {
        //xxxxx.jsondb
        let db = x.data;
        let title = db.title;   //title 1
        let info = db.info;   //title 2
        console.log(title); // 
        $("-sharpid").append("${title} -- ${info}");   //
    }
    });

Why is this?

Mar.28,2021

solve

Code modified to

$('-sharpid').append(`{$title} -- {$info}`);   //

reason

double quotation marks " is the literal amount of the string
, while the literal amount of the template string is `, that is, the button above the tab button
you have quoted it incorrectly, and it will not take effect

.

suggestions

similar questions, first go directly to mdn to see, which is authoritative and detailed

.

{$title} or ${title} ?


use backquotes
`
and look at your code should use text instead of append

Menu