php array:
Array([0] => http://XXX/xgsyw/content/Uploads/Img/1111.jpg[1] => http://XXX/xgsyw/content/Uploads/Img/222.jpg)
to javascript "images"
$('#top').bgStretcher({
images: ['images/sample-1.jpg', 'images/sample-2.jpg', 'images/sample-3.jpg', 'images/sample-4.jpg', 'images/sample-5.jpg', 'images/sample-6.jpg'],
slideDirection: 'N',
slideShowSpeed: 1000,
transitionEffect: 'fade',
sequenceMode: 'normal',
});
Encode it with the JSON
library. Send it back to the Javascript, decode it, and append new img
child nodes to some container.
echo json_encode(arrayOfImages);
Then in your JS:
var images = JSON.decode(returnValue);
images.each(function(path) {
var img = $('<img>');
img.attr('src', returnValue);
img.appendTo('#imagediv');
});
As noted in the comments..
It is quicker to use $(document.createElement("img"));
than to use the aforementioned suggestion.
You might have done some more research online, because what you need for your solution is the JavaScript Object Notation
short JSON.
Use json_encode($your_array);