-2
我真的很困惑,为什么我收到我的代码出现'Unexpected identifier'错误。唯一最近更改的是URL。.success UncaughtSyntaxError:意外的标识符
我正在开发一个项目,在等待我的项目合作伙伴设置Heroku时,我转向了这个假API。
这里是我的代码:
$('#username-submit').click(function() {
var userlinks = $('.user-links')
console.log('test');
$.ajax({
method: 'GET', //this is a GET git request
url: 'http://jsonplaceholder.typicode.com' //link to the API they created
beforeSend: function(xhr) {
xhr.setRequestHeader('Authorization', 'user name'); //takes the username and authorizes it
dataType: 'json',
.success(function(data) {
console.log(data);
})
}
})
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
你在你的var声明中忘记了一个';' – Li357
@AndrewL真的,但没有引起问题 - 它在那里是可选的,不是?问题在于发送给Ajax函数的参数。 –