$。阿贾克斯()和QUOT;未捕获的ReferenceError:数据没有定义" [英] $.ajax() and "Uncaught ReferenceError: data is not defined"
本文介绍了$。阿贾克斯()和QUOT;未捕获的ReferenceError:数据没有定义"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试了几种方式来获得.json文件和数据使用$ .getJSON和$。阿贾克斯()的 overthere
I tried out several ways to get .json file and data using $.getJSON and $.ajax() overthere
我的JS code n⁰2失败:
$.ajax({
type: "GET",
url: 'js/main.js',
data: data,
success: 1,
}).done(function ( data ) {
var items = [];
$.each(data.tata.entities.q142.labels.fr.value, function(key, val) {
items.push('<li id="' + key + '">Test 2:' + val + '</li>');
});
$('<ul/>', {
'class': 'my-new-list',
html: items.join('')
}).appendTo('body');
});
在Chrome浏览器的控制台,消息误差
"Uncaught ReferenceError: data is not defined"
指的是的行:
data: data,
这是怎么了?怎么办?
编辑:所有完成客户端
推荐答案
该问题可能是因为你没有定义的变量数据,所以尝试删除数据:数据
行,它看起来像你刚刚这将无法正常使用查询字符串的JavaScript文件:
The problem is being caused because you didn't define the variable data, so try removing the data: data
line, it looks like you're just getting a JavaScript file which wouldn't normally take a query string:
$.ajax({
type: "GET",
url: 'js/main.js',
success: success,
}).done(function ( data ) {
var items = [];
$.each(data.tata.entities.q142.labels.fr.value, function(key, val) {
items.push('<li id="' + key + '">Test 2:' + val + '</li>');
});
$('<ul/>', {
'class': 'my-new-list',
html: items.join('')
}).appendTo('body');
});
这篇关于$。阿贾克斯()和QUOT;未捕获的ReferenceError:数据没有定义&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文