local-host 2016-12-08 00:40 采纳率: 100%
浏览 45

使用jQuery的下拉列表

I am trying to implement a simple Jquery drop down.

HTML

<h2> Networked Graphs</h2>
<p> Select the node ID from the drop down to see graphs up to a depth of 5 </p>
<form id="my form">
  <label for="Node_type">Node_Type</label>
  <select id="dropdown_change">
    <option value="Customer">Customer</option>
    <option value="Phone">Phone</option>
    <option value="ID_Card">ID_Card</option>
  </select>
  <input type='submit' value='Submit'>
</form>

This is the jquery code:

var selectID = $("#dropdown_change").val();
$.ajax({
  type: "POST",
  url: '/echo/html/',
  data: {
    html: "<span>This is the ajax response...</span>",
    delay: 2
   },

   success: function(data) {
     showMsg('SUCCESS: ' + data);
   },

   error: function (xhr, textStatus, errorThrown) {
     document.getElementById('dropdown_change').selectedIndex = 0;
     showMsg('ERROR: ' + errorThrown);
     return false;
   }
});

})  // closes ?

Selecting from the drop down and clicking on the submit button should display the success message 'SUCCESS: This is the Ajax response'.

Even though I specify "type: POST" and SUCCESS as well as ERROR messages, it fails with the below error:

{"error": "Please use POST request"}

Here is the Jsfiddle. Trying to learn javascript/jquery.

  • 写回答

2条回答 默认 最新

  • 游.程 2016-12-08 00:51
    关注

    After jquery 1.9.0, you should use

    method: "POST"
    

    instead of

    type: "POST"
    

    Link

    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)