简体   繁体   中英

How do I send data like an array from an html file to another html page?

I want to send an array of values from an html file to another to plot a bar graph on a html page. I do not want to use any sever side languages but I am open to use js,json, jquery and ajax.

The array looks like: arrVisitors[0] = "a, 750"; arrVisitors[1] = "b, 425"; arrVisitors[2] = "c, 1000"; arrVisitors[3] = "d, 700"; arrVisitors[4] = "e, 800"; arrVisitors[5] = "f, 975"; arrVisitors[6] = "g, 375"; arrVisitors[7] = "h, 775"; So how do I store it in the 1st html file and how do I call it in the second file where I am plotting the graph based on the values.

You need to send the data as Post-Parameter to the server and use that data when processing the request for the second page.

Since you didn't specify what you want to do exactly, I can't be more precise ...

使用$_POST['data']捕获变量和$.post('your.html',{data:$('form').serialize()},function(data){alert(data);})

You can use LocalStorage - since it's isolated per domain it will be visible across all the subpages in your domain.

  • Page A: store the array you need in the localstorage.

    localStorage.setItem("name", ['my_array']) ;

  • Page B: listen for changes in the localstorage and act appriopriately when values are updated.

    window.addEventListener("storage", my_function, false);

No server-side language involved here. No strange hacks. Just pure HTML5.

http://diveintohtml5.info/storage.html

Considering that you have pure HTML files and there is no scripting language in place...

It would be difficult to get and process data passed from one html page in another one.. But you can do this operation using Javascript..

Pass the data with GET method of <form> and try to access that data on another page with the help of javascript. You can get the entire url by

window.location

and then you can use string functions to get all possible values.

Or you can use the local storage utility of html 5.

Check this link

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