jQuery.ajax({
            type: "post",
            async: false,
            url: "katongShop.aspx/GetJsonAvater",
            data: { biid: backgroundImageNumber, shiid: headImageNumber },
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            cache: false,
            success: function (bg) {
                //返回的数据用data.d获取内容
                jsonAvater = window["eval"]("(" + bg.d + ")");
            },
            error: function (err) {
                alert(err);
            }
        });
 [WebMethod]
    public static string GetJsonAvater(string biid , string shiid)
    {
        AvaterImage ai = GetAvaterBySHIIDandBIID(biid, shiid);
        string jsonStr;
        jsonStr = "[";
        for (int i = 0; i < listhdImage.Count; i++)
        {
            jsonStr += "{\"src\":\"" + ai.ImagePath + "\"},";
        }
        jsonStr = jsonStr.Substring(0, jsonStr.LastIndexOf(','));
        jsonStr += "]";
        jsonStr = jsonStr.Replace(@"\", "$");
        return jsonStr;
    }
错误信息:"Message":"无效的 JSON 基元: biid。","StackTrace":" 

解决方案 »

  1.   

    http://hi.baidu.com/helenyanh/blog/item/8889471692d67b04c83d6d62.html
      

  2.   

    data: { biid: backgroundImageNumber, shiid: headImageNumber },
    这里的问题
    data的写法不对,要写成data: '{ id: ' + id + ' }'注意data必须是一个“表示JSON对象的字符串”,而不是一个“JSON”对象原因是jquery会把JSON对象序列化成标准POST的形式,你此处的{ id: id }会变成形好id=3这样的形式,而ASP.NET WebService需要的是JSON格式的数据,所以必须把你的数据变成一个JSON样子的字符串
      

  3.   


     function sleep(numberMillis) { var now = new Date(); var exitTime = now.getTime() + numberMillis; while (true) { now = new Date(); if (now.getTime() > exitTime) return; } }
    $("#bigImage").attr("src", "Images/loading.gif");
            sleep(2000);
            $("#bigImage").attr("src", jsonAvater[0].src);
    邓肯帅哥   这段代码中  我想先显示loading图片 然后等待两秒  在显示jsonAvater[0].src这个图片  要怎么实现啊?
      

  4.   

    window.setTimeout(fn,2000);
    function fn(){
    $("#bigImage").attr("src", jsonAvater[0].src);
    }
      

  5.   

    $("#bigImage").attr("src", "Images/loading.gif");
    window.setTimeout(fn,2000);
    function fn(){
    $("#bigImage").attr("src", jsonAvater[0].src);
    }