javascript - 使用 xampp 服务器从 Javascript 向端口 3000 上的 nodejs 发送 ajax 请求
问题描述
我有一个适用于 xampp 的 php 项目。它运行良好。
我现在必须让这个项目与 NodeJS 一起工作。
我被告知将 ajax 的 URL(它具有我的 php 文件的 URL)更改为
http://localhost:3000/folder/script
这在 Postman 上运行良好。
但是我的请求总是失败()。我不知道如何阅读错误。它在 msj 中显示未定义。
这是我在本地服务器上正常工作但不能使用新 URL 的内容:
$.ajax({
data: { user: $userName, password: $password },
datatype: "json",
type: "get",
url: "http://localhost:3000/user/loginUser", ///If i put here my php URL it works fine
})
.done(function (data, textStatus, jqXHR) {
let obj = JSON.parse(data);
if (obj["Success"] == true) {
window.location = "forms/firstPage.php";
} else {
swal({ text: obj["Message"], icon: "warning" });
}
})
.fail(function (jqXHR, textStatus, errorThrown) {
swal({
text: "ERROR: " + jqXHR.responseText + ": " + errorThrown.responseText,
});
});
解决方案
推荐阅读
- django - 如何在 django 第三方应用程序中覆盖模型?
- c - 如果请求超过可用物理内存,如何让 malloc/calloc 失败(即不使用交换)
- dart - 为什么不能在 as 表达式中使用 Object.runtimeType?
- c# - 如何将 byte[] 类型的类变量发送到 Web 服务
- android - 如何在列表视图中显示带有 SSID 的 wifi 网络的 rssi?
- c# - 为什么 Button 在我的 datalist 控件中不起作用?
- go - 为什么我无法从我在 GCP 中托管的应用使用 Gmail SMTP 发送电子邮件?
- sql - 如何运行 while 循环以在 SQL 中运行动态查询?
- angular - 类型“EventViewerComponent”是 2 个模块声明的一部分:Angular 7
- azure - 如何在 Azure 中编写外部协作设置脚本