更改通过JSON传递的输入文本值


Change the Input Text Value Passed through JSON

我需要一点帮助。我将PHP中创建的数组中的对象加载到一系列输入框中。这些对象分别用于购物车:价格、数量和总价。虽然数据加载正常,但它似乎是只读的。

例如,quantity的输入文本值为1,我不能更改它。

我希望能够改变数量,而不必回到我的MySQL表。

我可以用普通的Ajax做得很好,但是当我使用普通的Ajax时,项目不会像我所有其他Ajax函数一样加载而不刷新。

代码如下:

   function updates(){ 
         $.getJSON("classes/cartlist.php", function(data) {
         $("#cart_list, #cart_table").empty(); 
            $.each(data.result, function(){ $("#cart_list, #cart_table").append(
                   "<tr id='"+this['id']+"'> 
                         <td> "+this['pro_title']+" </td> 
                         <td> <input type='text' id='price-"+this["p_id"]+
                                "' class='price' pid='"+this["p_id"]+
                                "'value='"+this["price"]+"' /> 
                        </td>
                   </tr> "); 
                 }); 
            }); 

这不是全部,但其他两个输入框是一样的。我想这样写会更容易读。

编辑:这是数量输入文本框的样子,因为有人问了。
<td><input type='text' id='qty-"+this["p_id"]+"' class='qty' pid='"+this["p_id"]+"' value='"+this["qty"]+"' />

编辑:好的,我找到了不能更改文本的原因那就是JSON

的set interval函数
  function done() {
            setTimeOut (
               function(){
                updates();
                }, 300)
             }

但是如果我删除了它,我就必须刷新页面才能得到我的数据。

我认为在

中追加字符串有错误
function updates(){ 
     $.getJSON("classes/cartlist.php", function(data) {
     $("#cart_list, #cart_table").empty();
        //make use of index and value inside function 
        $.each(data.result, function(index,value){ 
            // here some thing with your code because 'n indicate the end of statement so  
            $("#cart_list, #cart_table").append(
               "<tr id='"+this['id']+"'>" + 
                     "<td> "+this['pro_title']+" </td> "+
                     "<td> <input type='text' id='price-"+this["p_id"]+
                            "' class='price' pid='"+this["p_id"]+
                            "' value='"+this["price"]+"' />"+ 
                    "</td>"+
               "</tr> "); 
             }); 
        });