我有一个回复JavaScript的PHP脚本,在JavaScript中有PHP变量
echo '<script type="text/javascript">
FB.init({
appId: "myid",
channelUrl: "//mysite/channel.html",
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
xfbml: true // parse XFBML
});
FB.getLoginStatus(function (response) {
if (response.status === "connected") {
FB.api("me/bookvote:download", "post", {
book: "<?php echo "http://mysite/auction_details.php?name=$item_details["name"]&auction_id=$item_details["auction_id"]";?>",
fb:explicitly_shared = "true" //? Is syntactically valid but creates a global
}, //Missing a , here?
然而,我仍然得到:
Uncaught SyntaxError: Unexpected identifier for book: http://mysite.xom/auction_details.php?name=$item_details["name"]&auction_id=$item_details["auction_id"]";?>",
我该怎么办?
答案 0 :(得分:3)
我可以发现多个问题:
<?php ?>
标记。这显然不起作用。试试这个。我已经删除了回声。请注意,较大的PHP标记在那里结束。
?>
<script type="text/javascript">
FB.init({
appId: "myid",
channelUrl: "//mysite/channel.html",
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
xfbml: true // parse XFBML
});
FB.getLoginStatus(function (response) {
if (response.status === "connected") {
FB.api("me/bookvote:download", "post", {
book: "<?php echo "http://mysite/auction_details.php?name=$item_details["name"]&auction_id=$item_details["auction_id"]";?>",
fb:explicitly_shared = "true" //? Is syntactically valid but creates a global
}, //Missing a , here?
答案 1 :(得分:0)
更改此行:
book: "http://mysite/auction_details.php?name=' . $item_details["name"] . '&auction_id=' . $item_details["auction_id"] . '",
答案 2 :(得分:0)
这些变量从未转换为应该使用的实际值。 尝试通过连接将该字符串分成多个部分。
答案 3 :(得分:0)
你想要结束你的回音引用,就像这样:
echo '<script type="text/javascript">
....
book: "http://mysite/auction_details.php?name=' . $item_details["name"] . '&auction_id=' . $item_details["auction_id"] . '",
....