I have an array of strings that I would like to append to a url in an ajax request. There are some additional string that i need to add to the Url along with the array string.
html
<ul>
<li data-url="string1"></li>
<li data-url="string2"></li>
<li data-url="string3"></li>
<li data-url="string4"></li>
<li data-url="string5"></li>
</ul>
So far in my javascript i have something like this:
javascript
//create empty array
var data = [];
$('ul li').each(function(){
data.push(this.getAttribute('data-url'));
})
// now in data I have : ['string1','string2', 'string3' ..]
// here is where im lost
// how to concat those array items into the url with the '&' symbol
var url = 'www.foo.com/bar=' data + '&'
//Make an ajax request
$ajax({
url: url,
method: 'POST',
})
overall I would like the url to look something like this:
www.foo.com/bar=string1&bar=string2&bar=string3
barvalues? Don't you meanbar[]?