gpt4 book ai didi

javascript - var 声明中出现未终止的字符串文字错误

转载 作者:行者123 更新时间:2023-11-28 20:14:41 25 4
gpt4 key购买 nike

我已经声明了变量:

var myid=mydata.id;    
var imgpath="https://graph.facebook.com/<?=myid ?>/picture?type=small";

这给出了错误:

SyntaxError: unterminated string literal
var imgpath="https://graph.facebook.com/<br />`

我已经终止了它!御岳在哪里?

完整功能:

FB.api('/me?fields=movies,email', function(mydata) {
console.log(mydata.email);
console.log(mydata.id);
var myid=mydata.id;
var imgpath="https://graph.facebook.com/<?=myid ?>/picture?type=small";
//console.log(imgpath); ....}

最佳答案

<?=myid ?>是未定义的常量,PHP 将其解释为字符串。但在此之前,PHP 将打印错误并添加几行新行。

JS 不喜欢字符串中换行,因此会产生错误。

如果你想使用之前定义的 JS var,你必须这样使用它:

var imgpath = "https://graph.facebook.com/" + myid + "/picture?type=small";

关于javascript - var 声明中出现未终止的字符串文字错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19378572/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com