注册 登录
编程论坛 jQuery论坛

jquery发送ajax请求返回处理函数提醒缺少对象错误,求解!!!

hcw_bccn 发布于 2011-03-24 10:24, 5104 次点击
HTML代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www. xml:lang="zh" lang="zh" dir="ltr">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<script type="text/javascript" src="./jquery.js"></script>
<script type="text/javascript" src="./test.js"></script>
</head>
<body>
<ul>
    <li><a href="javascript:viod(0);" onclick="Navigation('home')">首页</a></li>
    <li><a href="javascript:viod(0);" onclick="Navigation('anli')">案例</a></li>
</ul>
<div id="home"></div>
<div id="anli"></div>
</body>
</html>

js代码:
function Navigation(eid) {
    obj = $("#"+eid);
    $.ajax({
        type: "POST",
        url: "test.php",
        data:'key='+eid,
        Type: 'text',
        timeout: 5000,
        beforeSend: function(){
            obj.html('请求中....');
        },
        error : function(msg){
            obj.html('请求失败!');
        },
        success: function(msg){
            obj.html(msg);
        }
    });
}

php处理代码:
<?php
if('home'==$_POST['key']){
    print_r('<font color=red><h1>HOME</h1></font>');
}
if('anli'==$_POST['key']){
    print_r('<font color=red><h1>ANLI</h1></font>');
}
?>

[local]1[/local]
1 回复
#2
aspic2011-03-28 10:50
直接访问test.php?key=home看看打印出来的东西
print_r改成echo看看呢 print_r应该是返回的数组吧
1