简体   繁体   English

ajax 调用后获取输入值

[英]Getting input value after ajax call

I have a table who's rows are generated from the database, and in each row there's a cell containing an input of type number, which I'm giving it as id like { id="quantity<?php echo $product->id?>" } so its stays unique.我有一个表,其中的行是从数据库生成的,并且在每一行中都有一个包含类型编号输入的单元格,我将其作为 id 给出,例如{ id="quantity<?php echo $product->id?>" }所以它保持独一无二。

I can successfully get the value in the first time ( before the ajax request that generates the table again from an another php page ).我可以在第一次成功获取值(在从另一个 php 页面再次生成表的 ajax 请求之前)。 But I try to get the value after ajax success but it gives me undefined .但是我尝试在 ajax 成功后获取值,但它给了我undefined

$(".card2").delegate(".buy", "click", function() {
  var order = 1;
  var id = this.value;
  var quantity = $('#quantity' + id).val();
  $.ajax({
    url: "order.php",
    type: "POST",
    data: {
      order: order,
      quantity: quantity,
      prodID: id
    },
    success: function(data) {
      $('.card2').html(data);
    }
  });
});

The data received from the ajax success is basically the whole table to be replaced in the div ".card2"从ajax接收到的数据成功基本上是整个表要替换在div“.card2”

You are replacing the entire table after the success call.成功调用后,您将替换整个表。 You replace the div element with the returned data by using $('.card2').html(data);您可以使用 $('.card2').html(data); 将 div 元素替换为返回的数据。 Inspect the returned 'data' and make sure you are including the same input button, id, handler, etc for the new table(in data) being rendered.检查返回的“数据”并确保为正在呈现的新表(在数据中)包含相同的输入按钮、ID、处理程序等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM