打开 PHP 文件可以看到数据 , 应该就是 JS 文件的问题.
代码如下 var box = {};
var remoteUrl = 'read.php'; 到这里应该都是没有问题的.
box.showBoxInfo = function() {
jQuery.getScript(remoteUrl, function(){
var boxInfoWrapper = jQuery('#boxInfoWrapper');
var html = box.getBoxHtml(data.PicUrl,data.Button1,data.Button2,data.Button3,data.Button4,data.Right);
boxInfoWrapper.html(html);
});
}
box.getBoxHtml = function(PicUrl,Button1,Button2,Button3,Button4,Right){
return '<div><a href="'+url+'">'+PicUrl+'</a></div>';}求解.新手学习.多多指教
代码如下 var box = {};
var remoteUrl = 'read.php'; 到这里应该都是没有问题的.
box.showBoxInfo = function() {
jQuery.getScript(remoteUrl, function(){
var boxInfoWrapper = jQuery('#boxInfoWrapper');
var html = box.getBoxHtml(data.PicUrl,data.Button1,data.Button2,data.Button3,data.Button4,data.Right);
boxInfoWrapper.html(html);
});
}
box.getBoxHtml = function(PicUrl,Button1,Button2,Button3,Button4,Right){
return '<div><a href="'+url+'">'+PicUrl+'</a></div>';}求解.新手学习.多多指教
index.html的代码为:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>jquery xml解析</title>
<script type="text/javascript" src="jq.js"></script>
<script type="text/javascript">
$(document).ready(
function(){
$.ajax({
url:"jquery1.php",
type:"get",
cache:false,
dataType:"json",
data:{},
success:function(data){$('#dd').html(data.com);},
error:function(na,data){alert(data);}
});
});
</script>
</head>
<body>
<div id="dd"></div>
</body>
</html> jquery1.php代码为:<?php
header("Content-type: text/html; charset=utf-8");//休正编码,传中文需要它!
header("ContentType:application/json");
$arr=array('name'=>'woaini','age'=>'1234','com'=>'中国人!');
echo json_encode($arr);
?>
PHP 页面就是这样的结果
echo json_encode($arr);你可以把我的PHP代码输出看看是什么样的:
{"name":"woaini","age":"1234","com":"中国人"}
我的数据是直接从数据库得出来的. JSON格式