Javascript 解析html页面中的内容

Javascript 解析html页面中的内容,javascript,jquery,html,css,Javascript,Jquery,Html,Css,需要根据从其他html页面获取的数据动态更新主页div中的内容 setInterval( function() { $.ajax({ type:'GET', url:"url for status", success : function(data){ console.log(data); } }) },3000); 在开发者工具控制台中打印的“数据”的内容是: <html>

需要根据从其他html页面获取的数据动态更新主页div中的内容

setInterval( function() {
    $.ajax({
        type:'GET',
        url:"url for status",
        success : function(data){
            console.log(data);
        }
    })
},3000);
在开发者工具控制台中打印的“数据”的内容是:

<html>

<style>
</style>

<head>
</head>

<script>
 var conns=[{num:1,
             id:1,
             Conn:[{type:'ppp',
                    Enable:1,
                    ConnectionStatus:'Disconnected',
                    Name:'CONNECTION_1',
                    Uptime:0,
                    ConnectionError:'TIME_OUT',
                    ..............
                  }]
            },
            {num:2,
             id:2,
             Conn:[{type:'ppp',
                    Enable:1,
                    ConnectionStatus:'Disconnected',
                    Name:'CONNECTION_2',
                    Uptime:0,
                    ConnectionError:'TIME_OUT',
                    ..............
                  }]
           }]
</script>

</html>

需要从该内容中提取ConnectionStatus、Name和ConnectionError,并将其显示在主页的相应div中。

我建议使用不同的传输类型,但是,您可以使用如下内容:

function break_out_each_id(){//returns array of indexes where id starts
    var i = 0;
    id_objs = [];
    while data.indexOf('id', i) > -1{
       id_objs[i] = data.indexOf('id', i);
       i++;
    }
    return id_objs
}

function find_values(){//pseudo code
     use the array of indexes from first index to next index
     in that string, do index of each value you are looking for (ConnectionStatus...)
     then parse that line after the ':' to get the value.
     Do this for each index in indexes array
}

对不起,这篇文章的伪代码太长了。正如我所说的,即使响应是字符串化版本,也最好以JSON的形式发送响应。在这种情况下,只需执行一个简单的JSON.parse即可

你能改变你接收数据的方式吗?如果是这样,最好发送json、xml或其他数据传输语言之类的响应。