首页 > 解决方案 > 使用 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,
    });
  });

标签: javascriptnode.jsxampp

解决方案


推荐阅读