简体   繁体   中英

How to pass the value of a list or an array from code behind to jquery?

Let's say I want to scan my local drive or a particular local folder for all images. What I want to do is get all the location of all the images and store it in a list/array then after that JQuery will going to refer to the list/array for a slideshow.

Please help me with this.

Putting this in your .aspx should do the trick. You can then reference imageList from your included Javascript. You need to include a reference to System.Web.Extensions.dll for JavaScriptSerializer

.aspx Page:

<html>
<head>
<script>
    var imageList = <%=new JavaScriptSerializer().Serialize(System.IO.Directory.GetFiles(@"C:\MyImages\", "*.png")) %>
    for(var i in imageList) {
        console.log(imageList[i]);
    }
</script>
...
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM