admin管理员组文章数量:1252691
I tried out several ways to get .json file and data using $.getJSON and $.ajax() overthere
My JS code n⁰2 fails :
$.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');
});
In Chrome console, the message error is :
"Uncaught ReferenceError: data is not defined"
Refering to the line :
data: data,
What is going wrong ? What to do ?
Edit: all is done client side.
I tried out several ways to get .json file and data using $.getJSON and $.ajax() overthere
My JS code n⁰2 fails :
$.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');
});
In Chrome console, the message error is :
"Uncaught ReferenceError: data is not defined"
Refering to the line :
data: data,
What is going wrong ? What to do ?
Edit: all is done client side.
Share Improve this question edited Apr 1, 2013 at 14:56 Hugolpz asked Apr 1, 2013 at 12:28 HugolpzHugolpz 18.3k28 gold badges105 silver badges191 bronze badges 2-
Do you have a variable somewhere where the data you want to send to the server is stored? It's trying to
GET
with some data attached in the form of a querystring?something=blah
– Henrik Andersson Commented Apr 1, 2013 at 12:30 -
1
Do you have any variable with name as
data
? if so please post that variable's data – Karthik Chintala Commented Apr 1, 2013 at 12:31
1 Answer
Reset to default 9The 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');
});
本文标签: javascriptajax() and quotUncaught ReferenceError data is not definedquotStack Overflow
版权声明:本文标题:javascript - $.ajax() and "Uncaught ReferenceError: data is not defined" - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740310143a2259246.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论