weixin_33708432 2016-12-27 09:46 采纳率: 0%
浏览 9

通过Ajax更新数据

I have the below code on href click I'm calling a javascript code in which an ajax is being called which returns the value of array $ss in json format . Now I want to know how can I update the value of $ss via ajax.

 <div class="white" id="white" style="display:none">   
        <?php
            foreach ($ss as $key => $value){
        ?>
        <a  href='javascript:void(0);'  onclick='callAjax('<?php echo $key; ?>')'>
        <?php   
           echo $value;
        ?>
        </a>
        <?php
           }
        ?>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script>
        var res;
        function on(id){
            //alert('hi '+id);
            $.ajax({
                url: 'ajax.php', //This is the current doc
                type: "GET",
                data: ({a: id }),
                success: function(data){
                    res = data;
                    //alert(res);
                    document.write(res);
                }
            }); 

        }

    </script>

And ajax.php files return array values for $ss. I understood how to update data of normal div through ajax but encountering problem to pass the data returned by ajax call to update array value.

  • 写回答

3条回答 默认 最新

  • weixin_33671935 2016-12-27 09:51
    关注

    1- Lets be clear javascript will not replace the content of a php variable.
    2- Even if so you will not be able to regenerate the html you need this way.
    3- after you receive your variable you need to update the html instead.

    PS: Surely you can update the variable on the server side when you receive that ajax call,
    that also needs some requirements(the variable is global and accessible inside the php file...),
    but from what I have understood you want to change it with javascript which is not possible.

    评论

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决