ajax - Get a distant text file with Javascript without Jquery -
this question has answer here:
i'm looking content of text file in javascript parse after. know how jquery, used call ajax function jsonp, but, time without framework.
i did code lot of try nothing succeed. here last version :
var url = 'https://url.com/videoslist.txt'; var xhr = new xmlhttprequest(); xhr.onreadystatechange = process; xhr.open("get", url, true); xhr.send(); function process() { if (xhr.readystate == 4) { console.log(xhr.responsetext); } }
the code seems ok browser (chromium) returns me :
> xmlhttprequest cannot load > https://url.com/videoslist.txt. origin > http://localhost:8888 not allowed access-control-allow-origin.
cross-site scripting not allowed under default security settings.. code work if requested url on same domain page came from.
if have control of remote server, can add header response:
access-control-allow-origin: *
but xmlhttprequest (or used be) different, between different browsers (mainly ie). means need "library shim", unify code across inconsistency.. i'd stick jquery if possible :)
here more references:
happy trails.
Comments
Post a Comment