0
votes

I tried to create a simple AJAX call to php script.

request.js

var xhr = new XMLHttpRequest();
xhr.open('GET', './assets/script/api/sample.php');

xhr.onreadystatechange = function() {
    if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status <= 207)) {
        console.log(xhr.responseText);
    }
}

xhr.send();

sample.php

<?php echo "Hello World"; ?>

Error:

Failed to load resource: the server responded with a status of 404 (Not Found) (localhost:7456/assets/script/api/sample.php)

1
is /assets/script/api/sample.php the correct path to sample.php?Bravo
Hi @Krissy please check sample.php path and file nameSaurabh Gujarani
it is a correct path.Krissy
what do you get if you put http://localhost:7456/assets/script/api/sample.php in your browser addressBravo
Could you have a rewrite rule on the server that's changing the path? Check the access log.Barmar

1 Answers

0
votes

Recently fixed this problem. The php file should be placed on the build folder.