将数组变量加载到div - ajax中

时间:2016-02-21 20:45:50

标签: jquery ajax

我有一个div如下:

<div id="#myid">

if($values){

echo "<p>$values['one']</p>";

echo "<p>$values['two']</p>";

}

</div>

现在,我想向服务器发送请求并将响应加载到我的div

            $.post('myurl', {target:target} , function(data){
                $('#myid').???(data);
            })

我不想覆盖div的所有内容。我只想将一个数组变量传递给我的div。我怎么办?

更新

我的div内容:

               <div id="product-quick-view-add-to-cart" class="mfp-with-anim mfp-hide mfp-dialog mfp-dialog-big clearfix">
                    <div class="row">


                        <div class="col-md-9">
                            <small><a class="text-muted float-to-right" href="#">$val1</a></small>
                            <br />
                            <h3 class="float-to-right">$val2</h3>
                            <br />
                            <br />

                            <p class="text-smaller text-muted float-to-right">$val2 </p>


                        </div>



                        <div class="col-md-3">
                            <div class="fotorama" data-nav="thumbs" data-allowfullscreen="1" data-thumbheight="50" data-thumbwidth="50">
                                <img src="$val3" alt="Image Alternative text" title="Gamer Chick" />
                            </div>
                        </div>

                    </div>



                    <div class="row">
                        <div class="col-md-10">

                            <hr class="hr-mt-5-mb-10" />

                            <span>
                                <div class="col-md-4 text-align-center">
                                    <p>$val4</p>
                                    <p>$val5</p>
                                </div>
                            </span>



                            <span>
                                <div class="col-md-4 text-align-center">
                                    <p>$val6</p>
                                    <p>$val7</p>
                                </div>
                            </span>


                            <span>
                                <div class="col-md-4 text-align-center">
                                    <p>val</p>
                                    <p>$val8</p>
                                </div>
                            </span>

                        </div>
                    </div>

                    <hr/><a class="btn btn-primary" href="#">add</a>
                </div>

1 个答案:

答案 0 :(得分:0)

您可以创建新的html代码或对象并附加到div:

$.post('myurl', {target:target} , function(res){
        var html = "<p>"+res+"</p>";
        $('#myid').append(html);
});