ExpressJS Pass variables to JavaScript

后端 未结 5 1373
谎友^
谎友^ 2021-02-07 12:35

I am completely lost on this; I am using NodeJS to fetch a JSON and I need to pass the variable to my page and have JavaScript use the data.

app.get(\'/test\', f         


        
5条回答
  •  故里飘歌
    2021-02-07 13:07

    Try the following:

    alert('!{myVar}')
    

    It's a good idea to JSON encode the data if is more than just a string.

    alert('!{JSON.stringify(myVar)}')
    

提交回复
热议问题