Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Ajax多次调用数组中的同一html类,如下[]_Php_Html_Ajax - Fatal编程技术网

Php Ajax多次调用数组中的同一html类,如下[]

Php Ajax多次调用数组中的同一html类,如下[],php,html,ajax,Php,Html,Ajax,我的密码在这里 <table id="tb" width="100% style="float:left; overflow:auto"> <tr > <th width="300px" style=" text-align: left; margin-left: 15px">Item</th> <th width="300px" style=" text-align:

我的密码在这里

  <table    id="tb" width="100% style="float:left; overflow:auto">
    <tr >
        <th width="300px" style=" text-align: left; margin-left: 15px">Item</th>
                    <th width="300px" style=" text-align: left; margin-left: 15px">Description</th>
        <th width="100px" style="font-size: 60%">Average<br> Price</th>

        <th width="150px">Quantity</th>
        <th width="150px">Price</th>
        <th width="150px">Discount</th>
        <th width="200px">Amount</th>
        <th width="50px"></th>
        <th></th>
    </tr>

    <tr style="height: 35px">


        <td><select style="font-size: 100% ;padding: 0 0 0 0; height: 30px; display: inline-block; width: 100%" ntype="text" 
                                        class="form-control item" name="item[]" required  >
                                            <?php $this->load->view('f-select-item'); ?></td>

        <td><input style="font-size: 100% ;padding-left: 10px; height: 30px; display: inline-block; width: 100%" ntype="text" 
                                        class="form-control" name="item_note[]"  /></td>
                                                                                    <td class="priced"><input 
                                                                                    style="height: 30px; text-align: right" pattern="[0-9]+"  value=""
                                        maxlength="10" minlength="0"  min='0' max='50000000' type="text" name="price1[]"  class="form-control ppp" /></td>


        <td><input style="height: 30px;text-align: right"  id ="num" maxlength="10" minlength="0"  pattern="[0-9]+" type="text" name="quantity[]"  class="form-control quantity"  /></td>

                                        <td><input style="height: 30px; text-align: right" pattern="[0-9]+"  maxlength="10" minlength="0"  min='0' max='50000000' type="text" name="price[]"  class="form-control price" /></td>

                                        <td><input style="height: 30px;text-align: right" pattern="[0-9]+" maxlength="10" minlength="0"  type="text" name="discount[]"  class="form-control discount"  /></td>
                                        <td><input  style="height: 30px;text-align: right" type="text"  maxlength="30" minlength="0"  name="amount[]" 
                                        class="form-control amount" value="" readonly/></td>

                                        <td style="height: 25px;text-align:right"><a href="javascript:void(0);" style="text-decoration: none; font-size: 80%; padding: 0 0 0 5; font-size:18px;" id="addMore" title="Add More Row">
                <span style="font-size:80%" class="glyphicon glyphicon-plus">
                </span>
            </a><a href='javascript:void(0);'  class='remove' title="Remove Row">
                                            <span  style="padding: 0 0 0 0; text-align:right; color:lightgray" class='glyphicon glyphicon-remove'></span></a></td>

                                        <td><input id ="num" style="text-align: right" type="hidden" name="amount1[]"  class="form-control amount1" style="font-size: 0%" value="0" />
                                        </td>

    </tr>                                       
</table>
”style=“高度:30px;文本对齐:右“pattern=“[0-9]+”value=“”
maxlength=“10”minlength=“0”min=“0”max=“50000000”type=“text”name=“price1[]”class=“表单控制ppp”/
此代码适用于一次呼叫

但是在jquet动态添加行之后,
td
是[]的几倍,所以我应该做什么..每个
td
应该有单独的响应…这次我调用每个td,但所有tds的响应都是相同的


请先回答…谢谢。

您不应该在循环中进行ajax调用,您应该在前一次调用成功后进行每次调用,而是在一个
setTimeout
函数中进行。下面是一个代码结构,它将递归地执行此操作,应该可以解决您的问题。您必须自己决定结束递归函数的条件:

function myAjaxCall(){
    $.ajax
({

type: "POST",
url: "pp",
data: dataString,
cache: false,
success: function(html)
{
$(".priced").html(html);

if(!/* the condition for Last ajax call*/)
  setTimeout(myAjaxCall,0);
} 
}); 

}
请注意,代码的另一个问题可能是每次调用后都要替换html。与其使用
$(.priced”).html(html);
不如使用
$(.priced”).append(html)
试试
jquery.on()
。Wordpress正在使用此函数。 里德博士: 用法:-


一种方法是给每个TD一个唯一的ID,并根据每个TD的唯一ID为每个TD放置正确的响应。但是,响应必须有哪个ID获得哪个HTML…您的示例代码不支持这样做,两端都没有一些更改。如何多次调用?这个TD是动态添加行jquery…多么可能…我认为是循环ajax..当我们添加行jquery DynamicCallyHow条件时,我们如何更改ID?我的意思是id1 id2 id3?…我是一个新的条件。除非您提供完整的代码,否则我无法帮助您处理该条件。您计算出的最后一个ajax调用的条件。或者您要生成的最后一个TD。您的循环已经具有的条件。如果是一个While循环,它已经有了一个条件,它是一个For循环,使用一个计数器变量可以帮助您。您能给我完整的代码吗?因为现在我已经更新了完全完成的代码。@Ramesh kitshiri HettiArachchi
  <?php
  // Database Connection
  $username = 'root';
  $password = '';
  $db = "acccccc";
  try {
  $conn = new PDO('mysql:host=mbhost;dbname='.$db.'', $username, $password);
   $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
   } catch(PDOException $e) {
   echo 'ERROR: ' . $e->getMessage();
    } 


    /////////////////////////////////////////////////////////////////////////////////////////////////

   if($_POST['id']){
   $id= $_POST['id'];
   $sql=$conn->prepare("select * from items where  '".$id."' in (c_v_id, item_id) ");
   $sql->execute();
   if($sql->rowCount() > 0){

                       $sum =     $amount= $q1 = $q2 = $am = $am1 = $am2 = $sumq =0;

                    while($row=$sql->fetch(PDO::FETCH_ASSOC)){




                        if($id == $row['c_v_id']){

                        $am = $row['amount'];
                        $q1 = $row['quantity'];

                        if($am != 0 and $q1 != 0 ){
                 $amount = $row['amount']/$row['quantity'];

                        } else{ $amount = 0;}
                        }elseif($id == $row['item_id']){

                            $am2 = $row['amount'];
                             $q2 = $row['quantity'];
                            if($am2 != 0 and $q2 != 0 ){
                            $amount = -$row['amount']/$row['quantity'];
                        }else{ $amount = 0;}
                        }
                    $sum += $amount;
                    $sumq = $q1 - $q2;
                    }
                    ?>
                    <input  title="<?php echo 'Available Quantity: '.$sumq; ?>" style="height: 30px; text-align: right" pattern="[0-9]+"  value="<?php echo $sum; ?>"
                                        maxlength="10" minlength="0"  min='0' max='50000000' type="text" name="price1[]"  class="form-control ppp" />

                    <?php 

     }else{ 


?>

<input  title="Zero Quantity" style="height: 30px; text-align: right" pattern="[0-9]+"  value="0"
                                        maxlength="10" minlength="0"  min='0' max='50000000' type="text" name="price1[]"  class="form-control ppp" />

                    <?php }


  }




 ?>
function myAjaxCall(){
    $.ajax
({

type: "POST",
url: "pp",
data: dataString,
cache: false,
success: function(html)
{
$(".priced").html(html);

if(!/* the condition for Last ajax call*/)
  setTimeout(myAjaxCall,0);
} 
}); 

}
$(document).on('click','.ajax-loaded-content',function(){ myfunc();})