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
Cocos does not support php. Why do you use it? Better to use js and your game will be cross-platform
I’m currently implementing it on Cocos Creator.
So, your target platform is only web?
Sorry for off-topic, just interesting
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.
It is now okay. The php file should be inside the build folder instead on the project folder.
clonaid
#7
xhr.open(‘GET’, ‘…/build/api-rate.php’); ???
or
xhr.open(‘GET’, ‘…/build/web-desktop/api-rate.php’); ???