weixin_33701294 2019-02-28 15:46 采纳率: 0%
浏览 21

接收用ajax发布的数据

I have this code for sending data with ajax to a update.php page

$(document).ready(function() {
  $("#modify").click(function() {
    var a = $("#a").val();
    var b = $("#b").val();
    var c = $("#c").val();
    $.ajax({
      type: "POST",
      data: {
        a: 'a',
        b: 'b',
        c: 'c',
        id: 'id'
      },
      url: "update.php",
      success: function(result) {

      }
    });
  });
});

In the update page, I receive data like this

id = $_POST["id"];
a = $_POST["a"];
b = $_POST["b"];
c = $_POST["c"];

Is it correct or does it have a problem, because that doesn't work.

  • 写回答

2条回答 默认 最新

  • 喵-见缝插针 2019-02-28 16:15
    关注

    That works very well, but i think you wrote the strings instead in the variables 'data' object.

     var a = $("#a").val();
        var b = $("#b").val();
        var c = $("#c").val();
        $.ajax({
          type: "POST",
          data: {
            a: a,
            b: b,
            c: c,
            id: id
          },
    
    评论

报告相同问题?