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:

http://www.cypressnorth.com/blog/programming/cross-domain-ajax-request-with-json-response-for-iefirefoxchrome-safari-jquery/

happy trails.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -