function getData() {
            $("#list").html(""); //清空列表中的数据
            //发送ajax请求
            $.getJSON(
    "jsondata.ashx", //产生JSON数据的服务端页面
    {name: "test", age: 20 }, //向服务器发出的查询字符串(此参数可选)
            //对返回的JSON数据进行处理,本例以列表的形式呈现
    function(json) {
        //循环取json中的数据,并呈现在列表中
这里是主要问题,如果通过参数,没有查到数据,这里应该怎么写,还有jsondata.ashx里面应该怎么写???
        $.each(json, function(i) {
            $("#list").append("<li>name:" + json[i].name + "&nbsp; Age:" + json[i].age + "</li>")
        })
    })
        }

解决方案 »

  1.   

    if(typeof(json)=="undefined" || json.length=0){
     } 
      

  2.   

    不对,现在想知道,如果没有数据jsondata.ashx这个文件里应该怎么写??
      

  3.   

    <%@ WebHandler Language="C#" Class="jsonData" %>using System;
    using System.Web;public class jsonData : IHttpHandler {
        
        public void ProcessRequest (HttpContext context) {
            context.Response.ContentType = "text/plain";
            假如没有查到数据 string data=?????                   
            context.Response.Write(data);
        }
     
        public bool IsReusable {
            get {
                return false;
            }
        }}
      

  4.   

    var result=xmlHttp.responseText;
    var json=eval("("+result+")");
    if(json.PassInfo!="" && json.PassInfo.length>0)
    {}
    返回默认空值
      

  5.   

    我传一参数,能查询到数据,以JSON格式返回,没有数据,我怎么返回??页面上又如何判断没有返回,给个具体的代码。