There is some file.txt on another domain. How to write to a variable its contents? On jquery. I ran into the problem of the browser barring cross domain Ajax. X-allow-origin is not an option.

  • @ Anton Suslov, If you are given an exhaustive answer, mark it as correct (click on the check mark next to the selected answer). - Deleted
  • On jQuery - no way. Need a server. - ling

3 answers 3

What does jquery have to do with it? This is generally a framework, and not some kind of language and new features, it does not, it makes the js code more convenient for writing and reading ... Well, all right, quite simply:

$stream = file_get_contents("http:fff.fff/file.txt"); 

Well, in js, you can:

 var stream = '<?=$stream?>'; 
  • the fact of the matter is that it is necessary on the client side - SPAHI42
  • I think you do not have the right architecture and thoughts in general, probably you are doing something wrong, since you have reached such a perversion. - johniek_comp
  • Well, that's exactly the way. Not for me. - SPAHI42

No Browser security policies prohibit getting the contents of files from third-party domains into variables using js.

    If X-allow-origin is disabled, then only the option with JSONP. There are no other possibilities. This is the safety standard.