Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation since 09/14/2021 in Posts

  1. You cannot return the data, you have to do something with it. Print it, manipulate it, store it into a variable or something else. In my previous example, I used console.log() to write the data to the Javascript console. Javascript is not allowed to write to files, neither on the server nor on the user's computer, but you can prompt the user to download a generated text file like this: <script> function file_get_contents(filename, callback) { fetch(filename).then((resp) => resp.text()).then(callback); } function handleResponse(data) { // This code generates a text file with the data and asks the user to download it var blob = new Blob([data], { type: "text/plain;charset=utf-8" }); var a = document.createElement("a"); a.href = URL.createObjectURL(blob); a.download = "file.txt"; document.body.appendChild(a); a.click(); setTimeout(function() { document.body.removeChild(a); window.URL.revokeObjectURL(url); }, 0); } file_get_contents('https://mediainfo.tf1.fr/mediainfocombo/L_LCI?context=MYTF1&pver=4014002', handleResponse); </script>
    1 point
  2. The code will need to be updated so that you are handling the data in the callback function. It actually cannot work identical to PHP's function because it's asynchronous. This would work: <script> function file_get_contents(filename, callback) { fetch(filename).then((resp) => resp.text()).then(callback); } function handleResponse(data) { // Do something with the data here console.log(data); } file_get_contents('https://mediainfo.tf1.fr/mediainfocombo/L_LCI?context=MYTF1&pver=4014002', handleResponse); </script>
    1 point
  3. Looking at the HTTP headers, they are not permitting cross-origin requests on that file.
    1 point
  4. Not from other websites. Browsers implement this restriction for security purposes. Applications that want to work around the restriction will have a back-end script which fetches content from other websites and sends it to the front end.
    1 point
  5. As with all AJAX-style APIs, with fetch() you're only permitted to load files from your own server unless the target server has granted permission to your website.
    1 point
  6. https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_draggable <script> //Make the DIV element draggagle: dragElement(document.getElementById("mydiv")); It should be "draggable", but instead it's "draggagle".
    0 points
×
×
  • Create New...