javascript 如何使用 XAMPP 或 node.js 使 AJAX 在本地服务器上工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22273738/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 22:49:08  来源:igfitidea点击:

How to make AJAX work on local server using XAMPP or node.js

javascriptjqueryajaxnode.jsxampp

提问by Les Paul

I am at my wit's end and I'm hoping someone can help.

我不知所措,希望有人能提供帮助。

I have been trying to get AJAX to work on a local server, but I don't know where to begin even with the most basic code. I have downloaded node.js and XAMPP and I have been looking online for tutorials on how to get even AJAX test sites to work.

我一直试图让 AJAX 在本地服务器上工作,但即使是最基本的代码,我也不知道从哪里开始。我已经下载了 node.js 和 XAMPP,并且一直在网上寻找有关如何让 AJAX 测试站点工作的教程。

If anybody knows of a step-by-step tutorial on how to get the most basic AJAX functions to work on node.js or XAMPP I would appreciate it so much. Everything I've found seems to assume the person reading already knows how to begin working with a local server to make the code work. I know what code I need to write from all the examples, I just don't know how to get it to work on XAMPP or node.js! Thank you.

如果有人知道有关如何让最基本的 AJAX 函数在 node.js 或 XAMPP 上工作的分步教程,我将不胜感激。我发现的一切似乎都假设阅读的人已经知道如何开始使用本地服务器来使代码工作。我知道我需要从所有示例中编写什么代码,我只是不知道如何让它在 XAMPP 或 node.js 上工作!谢谢你。

采纳答案by Steven Martin

is XAMPP working? can you access it via http://localhost?

XAMPP 工作吗?你可以通过访问它http://localhost吗?

AJAX is just javascript that can send requests without reloading the entire page. it doesn't need anything special to work.

AJAX 只是 javascript,它可以在不重新加载整个页面的情况下发送请求。它不需要任何特殊的工作。

however its important that localhost is working and keep note if you need to add a port to the end of the url to get it to work.

但是,重要的是 localhost 正在工作,如果您需要在 url 的末尾添加端口以使其工作,请注意。

then add your html/php file into the htdocs folder of XAMPP and navigate to it using the localhost url.

然后将您的 html/php 文件添加到 XAMPP 的 htdocs 文件夹中,并使用 localhost url 导航到它。

回答by usefulBee

In case you have Visual Studio installed. Click

如果您安装了 Visual Studio。点击

  1. File Menu
  2. Open
  3. Web site
  4. Select the website folder
  5. Hit F5 to run the app
  1. 文件菜单
  2. 打开
  3. 网站
  4. 选择网站文件夹
  5. 按 F5 运行应用程序

回答by Sidus

First, you have to create your html file; do it in the "htdocs" folder of XAMPP, which is likely to have its folder on your C: hard drive path, unless you moved it elsewhere.

首先,您必须创建您的 html 文件;在 XAMPP 的“htdocs”文件夹中执行此操作,除非您将其移动到其他位置,否则该文件夹很可能在您的 C: 硬盘驱动器路径上。

Secondly, start XAMPP Apache server. Now you can access your html web page via web browser at "localhost/yourwebpage.html".

其次,启动 XAMPP Apache 服务器。现在,您可以通过 Web 浏览器“localhost/yourwebpage.html”访问您的 html 网页。

Hope this help everyone!

希望这对大家有帮助!