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.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度