- 論壇徽章:
- 0
|
本帖最后由 windyfocus 于 2014-10-14 11:36 編輯
大家好 很早就加入cu了,今天第一次求助,實在是項目緊張另加疲倦,忘大牛能指點一二 ,目前的大概的代碼如下,目的是希望能通過setInterval 每隔3秒局部更新數(shù)據(jù),引用了jquery.js
目前個人認為關(guān)鍵問題是這句: setInterval($( devipid).html( devipval),3000 );
firefox訪問的時候firebug提示:
SyntaxError: missing ] after element list
[object Object]
另外還有個問題想咨詢:除了iconv還有別的簡單的辦法進行ascii轉(zhuǎn)utf-8嗎?如您所見,json數(shù)據(jù)里部分內(nèi)容其實應(yīng)該是中文,非常感謝 !
html文件中關(guān)鍵腳本:
$(document).ready(function(){
// setInterval($("#dev_ip_100").html('1000000'),3000);
// setInterval(doit(),3000);
$.post("http://localhost:8080/pingbiqi/KEYPHP/ajax2.php",function(json){
for ( var i = 0; i < json.length; i++)
{
// alert( json.dev_ip);
var devipid='dev_ip_' + json.id ;
//$("#" + devipid).html(json.dev_ip) ;
var devipval = json.dev_ip;
devipid="#" + devipid
//alert(devipid);
//alert(devipval);
setInterval($( devipid).html( devipval),3000 );
}
},"json"//
);
訪問 http://192.168.0.122:8080/ajax2.php 會返回如下data:
[{"dev_ip":"1.2.3.41","location":"new1","id":"100","status":"open","conn_status":"timeout","work_status":"abnormal"},{"dev_ip":"123.103.3.2","location":"new","id":"101","status":"close","conn_status":"timeout","work_status":"abnormal"},"}]
ajax2.php關(guān)鍵代碼:
$myjson = my_json_encode($arr);
// $myjson=iconv(us-ascii,utf-8,$myjson)
//if ($argv[1] === 'list')
//{
echo $myjson;
//}
//if ($argv[1] === 'summary')
//{
// echo $summary;
//}
function my_json_encode($phparr)
{
if(function_exists("json_encode"))
{
return json_encode($phparr);
}
else
{
require_once 'json/json.class.php';
$json = new Services_JSON;
return $json->encode($phparr);
}
} |
|