duangan6636 2018-07-25 07:37
浏览 597

为什么我会收到405错误?

I'm very new to web programming, and I'm trying to set up a little website with a serverside. Here's the code:

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>

The php code is here:

<?php
  session_start();
  $dropDownSelection = $_POST['userSelection'];
  echo $dropDownSelection
  //$dropDownSelection = $dropDownSelection . "wurde verarbeitet!";
?>

I'm running my server with node.js on localhost, port 8080. So far it works, when I've started the server I can load my page and interact with it. However, when I'm pressing the button, which triggers the AJAX call to the php, I'm getting the following error in my console log:

jquery-3.3.1.min.js:2 POST http://localhost:8080/MyFirstPhP.php 405 (Method Not Allowed)

I must add that I'm running the whole thing without admin privileges. However, since the webserver somehow seems to run as I can load the website, I wonder if it could be due to another reason than low privileges on the machine.

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 lammps拉伸应力应变曲线分析
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
    • ¥30 python代码,帮调试,帮帮忙吧