发送 get 请求时,我似乎遇到了一个非常奇怪的错误,我在同一台服务器上同时运行 PHP 和 javascript 代码,所以没有来源问题。错误:
Uncaught SyntaxError: Unexpected identifier
OPTIONS http://localhost/Scores.php
Uncaught SyntaxError: Unexpected identifier
在这条线上:
req.send("&name="+username+"&pw="+password);
我的完整代码:
function initiateLoginSequence() {
var isnewplayer=prompt("Hello! Are you new?(Y/N)");
if(isnewplayer == "N") {
var username = prompt("Enter username.");
var password = prompt("Enter Password.");
} else {
var username = prompt("Enter a username. This will be used for future logins.");
var password = prompt("Enter a password. This will be used for future logins.","*");
var req = new XMLHttpRequest();
req.open('GET', 'http://localhost/Scores.php', true);
req.send("&name="+username+"&pw="+password);
}
}