var a;
var urlArray = [];
$("a").each{function(){
a = $(this).attr("href");
urlArray.push(a);
});
var sArray = [];
$.each(urlArray, function(x, y){
$.ajax({
url: y, // pass the URLs consecutively
type: 'get',
dataType: 'html',
success: function(data){
sArray.push( $("video").attr("src") );
}
})
});
log(sArray); // returns a single URL, not array as expected
I've been attempting to retrieve src
values of <video>
elements via $.Ajax
calls. I try and pass an array of URLs consecutively to $.Ajax
via $.each
, but results logged from success:
only come from a single URL. I expect an array returned, but am only able to .push
one value into sArray.
Can someone explain how I can manage to consecutively retrieve the data I need from each URL sent to $.Ajax? Thank you.
Note: Put simply, I need to pass an array of URLs to $.Ajax so that I can retrieve data from every one of those URLs.