how we can send the Javascript
array as a parameter in the ajax
get call. I am working with the API call and i have the API call method that has three parameters and the third one is the array.
我们如何将Javascript数组作为参数发送到ajax get调用中。我正在使用API调用,我有API调用方法,它有三个参数,第三个是数组。
2 个解决方案
#1
0
You can do like this
你可以这样做
demArray = [];
demArray[0] = 'hi';
demArray[1] = 'hello';
$.ajax({
type: "GET",
data: {arrayDem:demArray},
url: "someUrl",
success: function(response){
}
});
Also serialize()
& serializeArray()
can help you.
serialize()和serializeArray()也可以帮到你。
#2
0
If you are getting those arrays from a form you could:
如果您从表单中获取这些数组,您可以:
var form = $('#form').serialize();
$.ajax({
type: "GET",
data: form,
url: "foo.php",
success: function(data){
}
});
Else you could just pass the parameters into data:
like:
否则你可以将参数传递给数据:例如:
data: {foo:Array}
#1
0
You can do like this
你可以这样做
demArray = [];
demArray[0] = 'hi';
demArray[1] = 'hello';
$.ajax({
type: "GET",
data: {arrayDem:demArray},
url: "someUrl",
success: function(response){
}
});
Also serialize()
& serializeArray()
can help you.
serialize()和serializeArray()也可以帮到你。
#2
0
If you are getting those arrays from a form you could:
如果您从表单中获取这些数组,您可以:
var form = $('#form').serialize();
$.ajax({
type: "GET",
data: form,
url: "foo.php",
success: function(data){
}
});
Else you could just pass the parameters into data:
like:
否则你可以将参数传递给数据:例如:
data: {foo:Array}