将 GET 请求从 xmlHttpRequest 发送到 php 文件 错误:连接 ECONNREJECT 127.0.



我试图使用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的库。这是该库的链接。希望对您有所帮助。

相关内容

最新更新