javascript - 为什么我会收到 405 错误?
问题描述
我对网络编程很陌生,我正在尝试建立一个带有服务器端的小网站。这是代码:
class userData {
catchDropDownSelection() {
this.dropDownSelection = $('#xDropDown').prop('selectedIndex');
}
}
class sendData {
constructor(userData) {
this.userDataClone = userData;
}
sendDropDownSelection() {
//this.userDataClone.catchDropDownSelection();
$.post("MyFirstPhP.php", {
userSelection: "dummy" //this.userDataClone.dropDownSelection
}, function(data) {
//this.testFunction()
$('#testOutput').html("data");
//document.getElementById("testOutput").innerHTML = "data"
}).fail(function() {
console.log("$.post failed!");
})
}
testFunction() {
//document.getElementById("testOutput").innerHTML = "data"
$('#testOutput').html("data");
}
}
var userDataInstance = new userData;
var sendDataInstance = new sendData(userDataInstance);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<title>PHP is Awesome!</title>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="MyFirstPhP.css">
</head>
<body>
<select id="xDropDown">
<option value="test1">test1</option>
<option value="test2">test2</option>
</select>
<button onclick="sendDataInstance.sendDropDownSelection()">ClickMe!</button>
<p id="testOutput">not yet</p>
<script src="MyFirstPhP.js"></script>
</body>
</html>
php代码在这里:
<?php
session_start();
$dropDownSelection = $_POST['userSelection'];
echo $dropDownSelection
//$dropDownSelection = $dropDownSelection . "wurde verarbeitet!";
?>
我在 localhost 端口 8080 上使用 node.js 运行我的服务器。到目前为止,它可以工作,当我启动服务器时,我可以加载我的页面并与之交互。但是,当我按下触发对 php 的 AJAX 调用的按钮时,我的控制台日志中出现以下错误:
jquery-3.3.1.min.js:2 POST http://localhost:8080/MyFirstPhP.php 405(方法不允许)
我必须补充一点,我在没有管理员权限的情况下运行整个事情。但是,由于网络服务器似乎以某种方式运行,因为我可以加载网站,我想知道这是否可能是由于机器上的低权限以外的其他原因。
解决方案
推荐阅读
- android - 房间数据库在加载聊天时获取最后的聊天消息
- python - 无法添加 BinarySubTree
- flutter - ListView 与最喜欢的项目
- python - 如何将两个字典与里面的列表进行比较?
- mongodb - 如何将gitlab中的golang连接到gitlab-ci中的mongodb容器
- javascript - OpenLayers:将地图锁定到矢量的范围
- python - 如何在 polyfit() 的权重的两个变量中包含错误
- python-3.x - 从 base64 编码的文本文件中提取帧(视频)
- reactjs - 延迟图像完美加载,但当它们重新出现在视口中时必须突然重新加载
- javascript - 如何在Javascript中以百分比的机会从多个数组中获取一个随机对象?