admin管理员组文章数量:1389758
I have some code that work, but I need to add some variable to the data sent by ajax.
I know, I can put this variable in the array sended, but it's no good for me.
I want to add +'&count='+'second'
Maybe I can send second array, but how?
var arr = new Array(1,2,3,4);
$.ajax({
type: 'POST',
url: baseUrl + "search/simple_filter",
data: {arr: arr}+'&count='+'second',
success: function (data) {
if (!data) console.log(data);
}
});
I have some code that work, but I need to add some variable to the data sent by ajax.
I know, I can put this variable in the array sended, but it's no good for me.
I want to add +'&count='+'second'
Maybe I can send second array, but how?
var arr = new Array(1,2,3,4);
$.ajax({
type: 'POST',
url: baseUrl + "search/simple_filter",
data: {arr: arr}+'&count='+'second',
success: function (data) {
if (!data) console.log(data);
}
});
Share
Improve this question
edited Jul 31, 2014 at 19:21
Simon Arnold
16.2k8 gold badges68 silver badges88 bronze badges
asked Jul 31, 2014 at 19:16
danildanil
1171 gold badge2 silver badges6 bronze badges
0
4 Answers
Reset to default 4Expand your base object, like so:
data: {arr: arr, count : 'second'}
var arr = new Array(1,2,3,4);
$.ajax({
type: 'POST',
url: baseUrl + "search/simple_filter",
data: {'arr': arr, 'count': second},
success: function (data) {
if (!data)
console.log(data);
}
});
To add a query string parameter in a POST request you would add it to the URL:
url: baseUrl + "search/simple_filter?count=" + second,
data: { arr: arr },
I assume that you want to use the value of the variable second
, not the string "second"
.
If you want to add the parameter in the POST data, and not as a query string parameter, you would add it to the object for the data
property:
url: baseUrl + "search/simple_filter",
data: { arr: arr, count: second },
You should add that to the POST URL and not the body:
var arr = new Array(1,2,3,4);
$.ajax({
type: 'POST',
url: baseUrl + "search/simple_filter"+'&count='+'second',
data: {arr: arr},
success: function (data) {
if (!data)
console.log(data);
}
});
本文标签: javascriptSend two arrays or array with variable via ajaxStack Overflow
版权声明:本文标题:javascript - Send two arrays or array with variable via ajax - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744697188a2620350.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论