编辑配置文件更新功能不起作用

时间:2014-08-26 06:31:20

标签: javascript php ajax

这是我的for循环,我必须在ajax请求后更新特定部分。 通过此代码数据库正在更新但部分未更新。

   <?php
            if ($prod ['data'] [0] [0] ['data'] ['name'] != null) {
                echo '
                            <div class="row">
                                <div class="col-md-12 products">
                                    <div class="heading_title">
                                        <label>Products</label>
                                    </div>';

                for($i = (count ( $prod ['data'] ) - 1); $i >= 0; $i --) {
                    echo '<div id="pd"><div class="products_data" id="pro_details' . $i . '">
                                        <label id="pro_name' . $i . '">' . $prod ['data'] [$i] [0] . '</label><div class="edit" style="display: none; margin-top:12px;margin-left: -20px;"><a onclick="editProduct(' . $i . ')"><img alt="edit_icon" src="images/edit-icon.png" class="edit_link edit"></a></div>
                                        <p><a href = "' . urldecode ( $prod ['data'] [$i] [1] ) . '" id="pro_url' . $i . '">' . urldecode ( $prod ['data'] [$i] [1]) . '</a></p>
                                      <div><p id="pro_description' . $i . '">';
                    $str = base64_decode ( $prod ['data'] [$i] [2] );
                    if ($str [0] == "(") {
                        $str [0] = " ";
                    }
                    if ($str [strlen ( $str ) - 1] == ")") {
                        $str [strlen ( $str ) - 1] = " ";
                    }
                    echo $str;

                    echo '</p></div>
                                    </div></div>



                                <div id="ed"><div class="products_data" id="pro_edit' . $i . '" style="display: none; padding-left: 25px;padding-top: 12px;">

                                            <div class="form-group">
                                                <div class="row">
                                                    <div class="col-md-4">  
                                                    <input type="text" class="form-control" name="edit_prodName" id="proName_edit' . $i . '" rows="1">
                                                        </div>  
                                                    <div class="col-md-8">
                                                    </div>  
                                                </div>
                                            </div>
                                            <div class="form-group">                        
                                                <div class="row">
                                                    <div class="col-md-4">  
                                                        <input type="text" class="form-control" placeholder="URL" name="edit_proURL" id="proURL_edit' . $i . '" rows="1">
                                                    </div>  
                                                    <div class="col-md-8">
                                                    </div>  
                                                </div>
                                            </div>
                                            <div class="form-group">                
                                                <div class="row">
                                                    <div class="col-md-11" width="96.666667%">
                                                        <textarea class="form-control" name="edit_proDescription" id="proDescription_edit' . $i . '" rows="3"></textarea>
                                                    </div>
                                                    <div class="col-md-1"></div>                
                                                </div>
                                            </div>  
                                             <input type="hidden" class="form-control" name="product" value="' . $ser_name [$i] . '" id="product' . $i . '">
                                                <div class="form-group">        
                                                    <div class="row">
                                                        <div class="col-md-8"></div>
                                                        <div class="col-md-2">              
                                                            <button class="btn btn-danger response button_class" onClick="updateProduct(' . $i . ','.$prod ['data'] [$i] [3].')">Done</button>
                                                        </div>
                                                        <div class="col-md-2">
                                                            <button class="btn btn-danger response button_class" style="margin-right: 5px;" onClick="closeProductEdit(' . $i . ');">Cancel</button>
                                                        </div>
                                                    </div>  
                                               </div>       
                                    </div></div>';

                            }
                              echo '</div>
                                      </div>';
                                }
                                    ?>

我必须使用ajax请求更新此循环。这是我的ajax功能:

    function updateProduct(p,c){
            var pdt= "#pro_details"+p;
            var ped = "#pro_edit"+p;
            var product = "pro_name"+p;
            var pne = "proName_edit"+p;
            var pue = "proURL_edit"+p;
            var pde = "proDescription_edit"+p;
        alert(c);

            var tno = p;
            var pnee = document.getElementById(pne).value;
            var puee = document.getElementById(pue).value;
            var pdee = document.getElementById(pde).value;
        var pro = document.getElementById(product).innerHTML;
            alert(pro); 
            $.ajax({
                url: "./xxxxxxxx.php",
                type: "POST",
                data: {
                    COMPANY:<?php echo '"'.$company.'"';?>,
                    NAME: pnee,
                    URL: puee,
                    DESCRIPTION: pdee,
                    id: c,
                    TNO: tno
                },
                success: function(data) {
                    $(ed).css("display","none");
                    $(pd).css("display","block");
                    $(pd).empty();
                    $(pd).html(data);
                }
            });
        }

如何更改关于ajax请求的特定部分。

1 个答案:

答案 0 :(得分:0)

这些行中使用的pded是什么?

success: function(data) {
                    $(ed).css("display","none");
                    $(pd).css("display","block");
                    $(pd).empty();
                    $(pd).html(data);
                }

您必须使用css选择器来选择ID为pded的元素。

将其更改为:

success: function(data) {
                    $("#ed").css("display","none");
                    $("#pd").css("display","block");
                    $("#pd").empty();
                    $("#pd").html(data);
                }