仅在使用 DNS 时 AJAX 请求上的 405(不允许的方法)

2023-09-23php开发问题
2

本文介绍了仅在使用 DNS 时 AJAX 请求上的 405(不允许的方法)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个非常奇怪的问题,我使用 AJAX 从我的 html 页面发送电子邮件,该页面链接到我在同一网站中的 PHP 页面.当我以 IP 模式1xx.xx.xxx.xxx:8080/mywebsite 进入网站时,AJAX 请求工作正常,只有当我使用链接到该 IP 地址的 DNS 时,才会出现此错误:

POST http://www.mywebsite.ma/sendEmail.php 405(方法不允许)

这是 AJAX 请求:

$.ajax({类型:POST",url: "sendEmail.php",数据:datastr,缓存:假,成功:功能(html){如果(html ==成功"){庆祝TheSuccessOfThisEmailSending();} 别的 {杀了我自己();}},错误:函数(){sumTingWong();}});

解决方案

我终于找到了问题所在,不知道是不是因为我对 Servers 和其他东西缺乏经验而没有看到.长话短说:我在服务器上安装了 Wamp,我使用 IP+端口来访问它,但是当我使用 DNS 时它直接指向网站文件(包括 php 文件)而它没有不经过Wamp.

我最终卸载了 Wamp 并将 PHP 包含在我的 IIS 服务器中以直接编译 PHP 文件,而无需安装另一台服务器.

我遵循了本教程 -> 如何在 Windows Server 2008 的 IIS 7 上安装 PHP

I have a really weird problem, I use AJAX to send an email from my html page, which links to a PHP page I have within the SAME website. The AJAX request works fine when I enter the website in IP mode 1xx.xx.xxx.xxx:8080/mywebsite only when I use a DNS that links to this IP address I get this error :

POST http://www.mywebsite.ma/sendEmail.php 405 (Method Not Allowed)

Here's the AJAX request :

$.ajax({
    type: "POST",
    url: "sendEmail.php",
    data: datastr,
    cache: false,
    success: function(html){
        if (html == "success"){
            celebrateTheSuccessOfThisEmailSending();
        } else {
            killMySelf();
        }
    },
    error: function() {
        sumTingWong();
    }
});

解决方案

I finally found the problem, I don't know how I didn't see due to my lack of experience with Servers and stuff. Long story short : I installed Wamp on the server, I used the IP+Port to access it, but when I use the DNS it directly points to the website files(including php files) and it didn't go through Wamp.

I ended up uninstalling Wamp and including PHP in my IIS server to directly compile PHP files without the need to install another server.

I followed this tutorial -> How to Install PHP on IIS 7 for Windows Server 2008

这篇关于仅在使用 DNS 时 AJAX 请求上的 405(不允许的方法)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17