douke6881 2016-01-19 06:30
浏览 20
已采纳

.load返回页面片段

I'm trying to load data from the output of a PHP called test2.php file and put it into a graph

HTML:

<html>
    <body>
        <div class="ct-chart ct-perfect-fourth"></div>
        <div id="data"></div>
    </body>
</html>

jquery:

$(document).ready(function(){
$("#data").load("test2.php #numbers ", function(result){
       console.log(result);
        var data = result.split(",").slice(1);
        var last_element = data[data.length - 1];

        new Chartist.Line('.ct-chart', {
        labels: data,
        series: [data]
        }, {
                fullWidth: true,
                height: 650,
                chartPadding: {
                    right: 0
                }

        });

    });


});

The graph shows 0 for the last number and console.log(result); returns:

<div id='number'>,-0.05,-0.07,-0.07,-0.07,0.14,0.14,0.09,0.07,0.07,0.07,0.07,0.65,0.63,0.63,0.63,0.63,0.63,0.58,0.56,0.56,0.56,0.56,0.84,0.79,0.77,0.77</div>

<html>
    <head>
        <meta charset="UTF-8">
    </head>
    <body>
        <form action="" method="post" enctype="multipart/form-data">
            <input type="file" name="pokerHand[]" id="pokerHand"  multiple="multiple" />
            <input type="submit" id="submit" value="submit" name="submit">
            <input type="hidden" name="test" value="abc" id="test" />
        </form>
    </body>
</html>

Wich is the output of my php file however <div id="data"></div> contans <div id='number'>[the numbers]</div> how do i get .load to return the same content that it loads to the page

  • 写回答

1条回答 默认 最新

  • dongyuruan2957 2016-01-19 07:12
    关注

    1) Change id name to numbers in test2.php because you use test2.php #numbers in ajax url.

    2) Use $(this).text() instead of result inside .load() callback function. It gives the text loaded in id=data, in our case it is numbers.

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

报告相同问题?

悬赏问题

  • ¥15 关于#网络安全#的问题:求ensp的网络安全,不要步骤要完成版文件
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥20 使用Photon PUN2解决游戏得分同步的问题
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM