Javascript ajax返回中的数组
我将数组存储在Js文件中,使用ajax我可以得到整个数组,谁可以得到横向数组Javascript ajax返回中的数组,javascript,jquery,html,arrays,Javascript,Jquery,Html,Arrays,我将数组存储在Js文件中,使用ajax我可以得到整个数组,谁可以得到横向数组 $.ajax({ type : "GET", url : "string-en.js", dataType : "script", success: function(data) { console.log('data is '+data);
$.ajax({
type : "GET",
url : "string-en.js",
dataType : "script",
success: function(data) {
console.log('data is '+data);
//label=data;
$(data.d).each(function(){
alert(this)
});
}
});
返回::
data is a = {"Hi":"Hi","By":"By" };
试试这个
$.each(data,function(i,v){
alert(v);
});
或者,如果您的数据是a
,则
$.each(data.a,function(i,v){
alert(v);
});
你的意思是“如何遍历数组”?使用
console.log
而不是alert
我有键/值对数组,使用ur get I get Error“Uncaught TypeError:无法使用'in'运算符在a={“Hi”:“Hi”,“By”:“By”}中搜索'26';返回包含整个数组的数据。你为什么使用脚本作为数据类型。。如果没有特殊原因,那么在ajax中使用数据类型:“json”、
,并将数组作为json返回。。。。我需要更改datayatype:“script”,我的js文件只包含数组??