jquery getjson无返回值 5
server.php页面<?phprequire_once'../global.php';global$king;$sf_id=kc_get('sf_id',2,1);$...
server.php页面
<?php require_once '../global.php';
global $king;
$sf_id=kc_get('sf_id',2,1);
$select2="select * from liuyan_select where level='1' and contact=$sf_id order by id ";
if(!$row=$king->db->getRows($select2,1))
$row=array();
$arr=array("id"=>1,"title"=>"石家庄");
//echo json_encode($arr);
echo urldecode(json_encode($arr));
exit;
?>
html页面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="{king:keywords/}" />
<meta name="description" content="{king:description/}" />
<title>{king:title/} - Powered by KingCMS for PHP</title>
<link href="../images/style.css" rel="stylesheet" type="text/css" />
<script src="../system/js/jquery-2.0.0b2.js" type="text/javascript"></script>
<script language="JavaScript">
function getSelectVal(){
var data=$("#sf_id").val();
alert(data);
$.getJSON("../feedback/server.php",{sf_id:data},function(json){
var ds_id = $("#ds_id");
alert(json);
$("option",ds_id).remove();
$.each(json,function(index,array){
var option = "<option value='"+array['id']+"'>"+array['title']+"</option>";
ds_id.append(option);
});
});
}
$().ready(function(){
getSelectVal();
$("#sf_id").change(function(){
getSelectVal();
});
});
</script>
</head>
<body>
<div id="top">
<span class="block fl w500 left">
<a href="{config:system.siteurl/}{config:system.inst/}"><img src="../images/logo.png"/></a>
</span>
<span class="block fl w500 right">
<strong>
<a href="{config:system.siteurl/}en/">English</a>
|
<a href="{config:system.siteurl/}">Chinese</a>
</strong>
</span>
</div>
<div id="topbanner">
<a href="/download/" class="download">下载使用</a>
<a href="/license/" class="license">许可协议</a>
<span class="version">当前最新版本是:{config:system.version/} (PHP)</span>
<a href="http://help.kingcms.com/" class="help">OnLine帮助文档</a>
<a href="" class="club" target="_blank">社区交流</a>
</div>
<div id="nav">
<a href="{config:system.siteurl/}{config:system.inst/}">{config:system.sitename/}</a> / {king:nav line="/" /}
</div>
<div id="main">
<h4 class="title">{king:title/}</h4>
<select name="sf_id" id="sf_id" title="选择省份">
{king:select1}
<option value="{king:id/}" >{king:title/}</option>
{/king:select1}
</select>
<select name="ds_id" id="ds_id" title="选择地市">
</select>
{king:inside/}
</div>
<div id="bottom">
<span class="block fl w500 left">
<a href="#">栏目2</a>
<a href="#">栏目3</a>
<a href="#">栏目1</a>
{king:menu3 line="|"/}
{king:menu/}
</span>
<span class="block fl right">
© 2004-2009 KingCMS.com All rights reserved.<br/>
{config:system.info/} {config:system.beian/}
</span>
</div>
</body>
</html> 展开
<?php require_once '../global.php';
global $king;
$sf_id=kc_get('sf_id',2,1);
$select2="select * from liuyan_select where level='1' and contact=$sf_id order by id ";
if(!$row=$king->db->getRows($select2,1))
$row=array();
$arr=array("id"=>1,"title"=>"石家庄");
//echo json_encode($arr);
echo urldecode(json_encode($arr));
exit;
?>
html页面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="{king:keywords/}" />
<meta name="description" content="{king:description/}" />
<title>{king:title/} - Powered by KingCMS for PHP</title>
<link href="../images/style.css" rel="stylesheet" type="text/css" />
<script src="../system/js/jquery-2.0.0b2.js" type="text/javascript"></script>
<script language="JavaScript">
function getSelectVal(){
var data=$("#sf_id").val();
alert(data);
$.getJSON("../feedback/server.php",{sf_id:data},function(json){
var ds_id = $("#ds_id");
alert(json);
$("option",ds_id).remove();
$.each(json,function(index,array){
var option = "<option value='"+array['id']+"'>"+array['title']+"</option>";
ds_id.append(option);
});
});
}
$().ready(function(){
getSelectVal();
$("#sf_id").change(function(){
getSelectVal();
});
});
</script>
</head>
<body>
<div id="top">
<span class="block fl w500 left">
<a href="{config:system.siteurl/}{config:system.inst/}"><img src="../images/logo.png"/></a>
</span>
<span class="block fl w500 right">
<strong>
<a href="{config:system.siteurl/}en/">English</a>
|
<a href="{config:system.siteurl/}">Chinese</a>
</strong>
</span>
</div>
<div id="topbanner">
<a href="/download/" class="download">下载使用</a>
<a href="/license/" class="license">许可协议</a>
<span class="version">当前最新版本是:{config:system.version/} (PHP)</span>
<a href="http://help.kingcms.com/" class="help">OnLine帮助文档</a>
<a href="" class="club" target="_blank">社区交流</a>
</div>
<div id="nav">
<a href="{config:system.siteurl/}{config:system.inst/}">{config:system.sitename/}</a> / {king:nav line="/" /}
</div>
<div id="main">
<h4 class="title">{king:title/}</h4>
<select name="sf_id" id="sf_id" title="选择省份">
{king:select1}
<option value="{king:id/}" >{king:title/}</option>
{/king:select1}
</select>
<select name="ds_id" id="ds_id" title="选择地市">
</select>
{king:inside/}
</div>
<div id="bottom">
<span class="block fl w500 left">
<a href="#">栏目2</a>
<a href="#">栏目3</a>
<a href="#">栏目1</a>
{king:menu3 line="|"/}
{king:menu/}
</span>
<span class="block fl right">
© 2004-2009 KingCMS.com All rights reserved.<br/>
{config:system.info/} {config:system.beian/}
</span>
</div>
</body>
</html> 展开
2个回答
展开全部
先要看你的请求后台页面的路径有没对,能不能调用到页面,如果能,再看页面返回的数据格式是不是json的,最后再看返回值到客户端页面方法对不对,直接用.$.post(),$.get()试试也可以
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询