简体   繁体   English

谁能告诉我为什么我收到Uncaught SyntaxError:意外的字符串?

[英]Can anyone tell me why I am getting Uncaught SyntaxError: Unexpected string?

This is my code below. 这是我的下面的代码。

The error I get above will not move, I am trying lots of different variants. 我上面得到的错误不会移动,我正在尝试许多不同的变体。

var $token = $(this).attr('id');
var $itemId = $(this).find('input.id').val();
var $instaUrl = 'https://api.instagram.com/v1/media/"'.$itemId.'"/likes?access_token="'.$token.'"';
console.log($instaUrl);

Thanks 谢谢

JavaScript uses + for string concatenation: JavaScript使用+进行字符串连接:

var $token = $(this).attr('id');
var $itemId = $(this).find('input.id').val();
var $instaUrl = 'https://api.instagram.com/v1/media/"'+$itemId+'"/likes?access_token="'+$token+'"';
console.log($instaUrl);

You used the dot ( . ) from PHP. 您使用了PHP中的点( . )。

By the way, you do not need to use a dollar sign for variables in JavaScript! 顺便说一句,您不需要为JavaScript中的变量使用美元符号!

Use + for concatenation in javascript.It can also be done using the following methods: 在JavaScript中使用+进行串联。也可以使用以下方法完成:

a. 一种。 The addition operator ( + ) 加法运算符( +

b. b。 The assignment operator ( += ) 赋值运算符( +=

c. C。 The built-in concat method 内置的concat方法

ar $token = $(this).attr('id');
var $itemId = $(this).find('input.id').val();
var $instaUrl = 'https://api.instagram.com/v1/media/"'+$itemId+'"/likes?access_token="'+$token+'"';
console.log($instaUrl);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我会收到“Uncaught SyntaxError: Unexpected reserved word”? - Why am I getting "Uncaught SyntaxError: Unexpected reserved word"? 为什么我会收到 Uncaught SyntaxError:意外令牌:标识符 - Why am i getting Uncaught SyntaxError: unexpected token: identifier 为什么我得到:未捕获的SyntaxError:此处出现意外的令牌ILLEGAL - Why am I getting : Uncaught SyntaxError: Unexpected token ILLEGAL here 为什么收到“ Uncaught SyntaxError:JSON输入意外结束”? - Why am I getting 'Uncaught SyntaxError: Unexpected end of JSON input'? 谁能告诉我为什么我收到错误'无法读取未定义的属性'值''? P5.JS - Can anyone tell me why i am getting the error 'Cannot read property 'value' of undefined'? P5.JS 谁能让我知道为什么会收到此错误? - Can anyone let me know why am I getting this error? 任何人都可以告诉我为什么我无法删除待办事项列表中的项目? - can anyone tell me why i am unable to delete an item from the todo list? 谁能告诉我为什么我在控制台中收到 404 错误? - Can anyone tell me why I'm getting a 404 error in the console? 未捕获的语法错误意外字符串 - uncaught syntaxerror unexpected string 未捕获的SyntaxError:意外的字符串 - Uncaught SyntaxError: Unexpected string
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM