我试图使用 xmlHttpRequest
执行 php 文件以发送 GET 请求。遗憾的是,它总是返回错误:Error: connect ECONNREFUSED 127.0.0.1:80
这是我的index.js
文件
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
这是我发送 GET 请求的方式
var xmlRequest = new XMLHttpRequest()
xmlRequest.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log("This is response text " + this.responseText)
} else {
console.log("This is code " + this.responseText)
}
};
xmlRequest.open("GET","app.php?token=" + data, true)
xmlRequest.send()
这是我的 php
文件,与 index.js
位于同一目录中
<?php
$device = $_GET['token'];
$deviceToken = $device;
echo $device;
最佳答案
XMLHttpRequest
用于向特定服务器发送请求。但是你的问题是关于执行 php 文件,该 php 文件位于你的 node
项目中。
如果我没记错的话,我建议使用名为 exec-php
的库。这是 link对于那个图书馆。希望对您有所帮助。
关于javascript - 从 xmlHttpRequest 发送 GET 请求到 php 文件错误 : connect ECONNREFUSED 127. 0.0.1:80,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54285844/