php获取网页js中的json,从php获取json数据使用js读取显示到网页笔记
//json與數組轉換
$array = array("username" => "hellojson","age" => 23,"sex"=>"M");//定義php數組
$res=json_encode($array);
//var_dump($res);
echo $res;//將結果輸出到頁面
?>
HTML代碼
$(function(){
$(document).on("click",'.test',function(){
var id=$(this).attr("id");
var data={id:id}
//var aaa=[{"0":"1","id":"1","1":"hello","name":"hello","2":"","password":""},{"0":"2","id":"2","1"
// :"world","name":"world","2":"","password":""},{"0":"3","id":"3","1":"helloworld","name":"helloworld"
// ,"2":"","password":""}]
// alert(aaa[2].name)
$.ajax({
type:"GET",
data:data,
url:'xml.php',
dataType:"json",
success:function(msg){
if(msg){
var res=eval(msg);//在php中返回的數據如果不能直接使用可以轉換一下,使用eval()函數可以實現轉化。
//alert(res.username)
alert(res[1].name)//彈出要取的數據
//console.log(res)
}
}
});
})
})
在原生js中還可以使用JSON.parse()函數來轉為json格式,在php中已經轉化為json格式了可以直接獲取
alert(msg[0].name)//msg為返回的json格式
相關報道:
1)從python官網上下載windows下的安裝包python-2.7.3.msi并安裝 2)打開IDLE(python GUI),輸入 import sys sys.version 如果你的python是32位,將出現如下字符: 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] 這個時候LIBSVM的p 更多
現實中,經常要做的一項任務,是在文本中檢索某種模式。所謂模式,就是滿足一定規則的字符串的總稱,例如只由 更多
總結
以上是生活随笔為你收集整理的php获取网页js中的json,从php获取json数据使用js读取显示到网页笔记的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 大众最贵的车多少钱啊?
- 下一篇: fis pure开发php,50个精品网