javascript - Jquery .get not retrieving file -
i have code supposed read html file, split array , display parts of array, when going though alert, found $.get not getting file
<html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"> </script> </head> <body> <button onclick="myfunction()">update</button> <div id="div1"></div> <script> function myfunction() { var info = ""; $.get("../read_test/text.html", function(data) { somefunction(data); }); alert(info); var array = info.split("§n"); var people = array[1].split(","); (var = 0; < people.length; i++) { document.getelementbyid("div1").innerhtml = people[i] + "<br>"; } } function somefunction(data) { var info = data; } </script> </body> </html>
the directories on server , go so: sublinks->read_test->this_file.html,text.html
objective of file have along lines of "a§nb1,b2,b3,§n" , script split via "§n" "array[1]" , split via ",". lastly displays each part of newly created array on new line, file "a§nb1,b2,b3,§n" result in:
b1 b2 b3
please help
ajax asynchronous, make request , call next instruction , not wait response ajax request. need process inside of $.get
. success event.
i have changed delimiter character ¥. change same in text.html. problem have not mentioned character set utf8 , due not recognized special character , subsequently not able split string. have aldo document type html5.
<!doctype html> <html lang="en"> <head> <meta charset="utf-8" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> </head> <body> <button onclick="myfunction()">update</button> <div id="div1"></div> <script> function myfunction() { $.get("../read_test/text.html", function(data) { var info = data; var array = info.split("¥"); var people = array[1].split(","); (var = 0; < people.length; i++) { document.getelementbyid("div1").innerhtml += people[i] + "<br>"; } }); } </script> </body> </html>
Comments
Post a Comment