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 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据