而获取JSON数据使用ajax我得到意外令牌:错误
While fetching JSON data using ajax i am getting Unexpected token : error
我需要从url中获取数据返回的数据是JSON。但是当我试图取回时,我得到了
Uncaught SyntaxError: Unexpected token:
这是代码,请核对。
你能告诉我为什么我得到这个错误以及如何解决它吗?
$(document).ready(function () {
var Url = "https://www.nseindia.com/live_market/dynaContent/live_watch/get_quote/ajaxGetQuoteJSON.jsp?symbol=LIBERTSHOE";
$.ajax({
contentType: 'application/json',
dataType: 'json',
url: Url + '&callback=?',
success: function (data) {
alert(data);
},
error: function (jqXHR, text, errorThrown) { }
});});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
查找提琴链接https://jsfiddle.net/vbpradeep/kf9ad1t3/
似乎你不能在JSON中构建URL字符串
而不是像这样在JSON中创建:
url: Url + '&callback=?',
你可以把它加到原URL字符串的末尾:
var Url = "https://www.nseindia.com/live_market/dynaContent/live_watch/get_quote/ajaxGetQuoteJSON.jsp?symbol=LIBERTSHOE&callback=?'";
http://codepen.io/nilestanner/pen/pEOgZj 这将删除语法错误,尽管codepen仍然显示交叉原点错误。
我希望这能解决问题。
$(document).ready(function() {
var Url = "https://www.nseindia.com/live_market/dynaContent/live_watch/get_quote/ajaxGetQuoteJSON.jsp?symbol=LIBERTSHOE&callback=?";
$.ajax({
contentType: 'application/json',
dataType: 'json',
url: Url
}).then(function(data){
//What should happen in success scenarios
console.log('Success');
alert(data)
},function(data){
//what should happen in failure scenarios
console.log('Failure Block');
alert(data)
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
相关文章:
- React JS:未捕获(在承诺中)语法错误:在位置 0 的 JSON 中意外<令牌
- jQuery$.getJSON抛出意外令牌
- 为什么我在下面的..of循环中得到意外令牌
- 组件中的ReactJS意外令牌
- AngularJS $http GET 请求到本地 JSON 文件返回语法错误:意外令牌]
- 巴别塔,意外令牌 (15:33) ::.
- Sencha 2.0 和 Codeigniter RESTful API 生成未捕获的语法错误:意外令牌:
- 在事件上使用 jquery 时出现意外令牌
- JSON 中位置 4 处的意外令牌<
- 意外令牌 ) 在我的代码中
- Electron 和 Babel 6 异步/等待抛出意外令牌
- “JSON.parse(str)”返回“意外令牌c”,但str是一个字符串
- jQuery after() uncatch SyntaxError: 意外令牌 ILLEGAL
- 使用节点javascript的意外令牌ILLEGAL
- Javascript/JQuery-Chrome意外令牌
- Ajax 帖子未捕获语法错误:意外令牌非法
- angularjs-SyntaxError:请求从服务器返回时出现意外令牌
- jquery:使用ember的意外令牌C
- React本机项目中的意外令牌
- 解析有效的 JSON 得到“语法错误:意外令牌非法”