javascript - $.ajax() and "Uncaught ReferenceError: data is not defined" -
i tried out several ways .json file , data using $.getjson , $.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, message error is :
"uncaught referenceerror: data not defined"
refering to line :
data: data,
what going wrong ? ?
edit: done client side.
the problem being caused because didn't define variable data, try removing data: data
line, looks you're getting javascript file wouldn't take 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'); });
Comments
Post a Comment