weixin_33738578 2017-01-24 22:54 采纳率: 0%
浏览 32

如何发布.Ajax的Json?

i want to post two items into server by using ajax in java-script; based on server-side document the post url is like this

http://example.com/h/{first-item}/{second-item}

this is my java-script code:

  $('#add-order').on('click', function() {
    var name = $('#name');
    var drink = $('#drink');

    var order = ?? // my question is this part what should i add 

    $.ajax({
      type: 'POST',
      url: 'http://example.com/h/',
      data: order,
      contentType: 'application/json',
      success: function(data) {
       console.log("Data added!", data);
      }
    });
  });

and this is my HTML:

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>

    <div class="input-group">
        <h4>Add a Coffee Order</h4>
        <p>name: <input type="text" id="name"></p>
        <p>name_space: <input type="text" id="drink"></p>
        <button id="add-order">Add!</button>
    </div>

<script src="jquery.js"></script>
<script src="script.js"></script>
</body>
</html>

i am a new in ajax, thanks for your help.

  • 写回答

2条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 有偿找一份verilog语言的cnn代码带讲解
      • ¥15 关于#mysql#的问题:mysql 组内排名,取各组的销售金额前10
      • ¥15 有人用过颜色传感器吗?
      • ¥50 求一个SQL长料切短料的优化排版算法
      • ¥15 python 删除TXT文档中小写字母
      • ¥15 ValueError: not enough values to unpack (expected 2, got 0)
      • ¥15 js怎么禁止修改域名
      • ¥15 Cursor为什么在Windows11打不开
      • ¥30 java调用javacv遇到的问题
      • ¥15 如何使用matlab画出带宽100Khz,时长100ms信号的LFM形式的时频图啊