Php file not found

Php file not found
0

#1

I tried to call php script I created inside the project using ajax but returns a 404 not found error.

request.js

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

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

xhr.send();

this is the path of my php file in the project
db://assets/script/api-rate.php


#2

Cocos does not support php. Why do you use it? Better to use js and your game will be cross-platform


#3

I’m currently implementing it on Cocos Creator.


#4

So, your target platform is only web?

Sorry for off-topic, just interesting


#5

Yes. I was planning to GET request from php cause if I done it directly from javascript, it doesn’t let me access to a domain because of CORS policy.


#6

It is now okay. The php file should be inside the build folder instead on the project folder.


#7

xhr.open(‘GET’, ‘…/build/api-rate.php’); ???
or
xhr.open(‘GET’, ‘…/build/web-desktop/api-rate.php’); ???