doulang2311 2015-10-28 16:23
浏览 27
已采纳

以php(json)的形式检索变量

How do I retrieve the value I receive from the php file in json (echoed in id="show_result" from $show) as a php variable? I wanna be able to do further calculations in php on that variable in first.php

  • 写回答

1条回答 默认 最新

  • douzhanhui5662 2015-10-28 19:28
    关注

    Given the expected result of:

    {"show":246}
    {"show":100}
    

    Use $.getJSON() to better handle the results:

    <script>
        var localShow;
        $('#number').on('keyup',function(e){
            if(e.which == 13){
            var get_var_name = $(this).val();
                $.getJSON(
                    'result.php',
                    { number:get_var_name },
                    function(data,status){
                        console.log(data);
                        if(status == 'success'){
                            $('#show_result').text(data.show);
                            localShow = data.show;
                        } else{
                            alert('Status: ' + status);
                        }
                    }
                });
            }
        });
    </script> 
    

    The script should read the JSON and create data as an object. You can then call show using dot notation: data.show should result in the value 246 or 100 depending on the result.

    More details: http://api.jquery.com/jquery.getjson/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)