Skip to content
Advertisement

XMLHttpRequest and Fetch request to PHP file not working Svelte

I am unable to grab information from a PHP file on an external host using Svelte.

Oddly, though, the XMLHTTP request works when linking to a text file hosted on the web.

Here is my JS code:

JavaScript

And here is the HTML:

JavaScript

The output from my PHP file, which should simply be “example”, returns nothing. I am baffled by this problem, and using a fetch statement also does not work.

Any ideas?

Advertisement

Answer

Try to add this to the top of your php file:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement