【发布时间】:2017-05-08 16:09:04
【问题描述】:
这可能已经在其他地方得到了回答,但我一生都无法让它发挥作用。
这是我的html:
<!Doctype html>
<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="JS.js"></script>
</head>
<body>
<div>
</div>
</body>
</html>
这是我的 Js 文件:
$( document ).ready(function() {
console.log( 'ready!' );
$.ajax({
url: 'http://steamcommunity.com/market/priceoverview/?appid=730¤cy=3&market_hash_name=StatTrak%E2%84%A2%20M4A1-S%20|%20Hyper%20Beast%20(Minimal%20Wear)',
type: 'GET',
dataType: 'jsonp',
success: function(data) {
console.log(data);
var lowestprice = $( 'lowest_price' );
console.log($target);
}
});
});
查询的结果是:
{"success":true,"lowest_price":"48,--\u20ac","volume":"12","median_price":"51,02\u20ac"}
但我得到了error uncaught SyntaxError: Unexpected token :
在此先感谢您,我正在尝试 Web 编程并且正在苦苦挣扎,因为我更习惯于面向对象编程。
【问题讨论】:
-
报告的错误来自哪一行。您的 JSON 看起来不错,我看不出(在您发布的代码中)可能会引发该错误。您的代码包含
console.log($target)和$target没有在任何地方定义让我认为您没有显示所有相关部分 -
它通常会告诉你问题出在哪一行。 js 看起来不错
-
var lowestprice = $( 'lowest_price' );在.(类选择器)或#(id 选择器)未与'lowest_price'一起使用之前将不起作用 -
那个响应不是 JSONP。你不能只使用 JSONP 来绕过 CORS,api 需要支持它。
标签: javascript jquery html json syntax-error