当前位置: 代码迷 >> ASP.NET >> 各位前辈救命呀弄了一天了还是出有关问题
  详细解决方案

各位前辈救命呀弄了一天了还是出有关问题

热度:8890   发布时间:2013-02-25 00:00:00.0
各位前辈救命呀弄了一天了还是出问题
我用Jquery的getJson()加上.ashx文件读取数据,在自己电脑的IIS上运行一切正常,但是放到虚拟空间上之后就不能读出数据,用开发者工具查看,凡是与ajax有关的ashx文件都找不到又或是无法加载资源,开始以为是路径问题,后来调整自己电脑上运行正常,放到空间又不行仍然无法加载,以为是ashx的问题于是就换成aspx文件还是找不到,真邪门了,是不是jquery的getjOSN()方法有bug,麻烦各位前辈帮看一下,我要虚脱了,挥泪谢谢了!
Jquery代码(版本1.7.2)
JScript code
$(document).ready(function () {    GetSj();})function GetSj(data) {    $.getJSON("../ApplicationProcessing/ShowAllCommodity.aspx", data, function (data) {        $.each(data, function (key, val) {            var sTp = "<td><img alt='' src='../Picture/Commodity/" + val.CPath + "' style='width:60px;height:107px;' /></td>";            var sName = "<td><span style='color:#10c3f0;'><strong>" + val.Bname + "</strong></span><br/>" + WenZi(val.Cname); +"</td>";            var sSpecification = "<td>" + val.CSpecification + "</td>";            var sInventory = "<td>" + kucun(val.CInventory) + "</td>";            var dRetail = "<td>" + GSH(val.CRetail) + "</td>";            var dPrice = "<td>" + GSH(val.CPrice) + "</td>";            var dNo = "<td ><input id='Text1' type='text' style='width:60px;' value='0' />件</td>"            var cz = "<td><a href='#'>订购</a>&nbsp;<a href='#'>收藏</a></td>";            $("<tr style='height:125px;'>" + sTp + sName + sSpecification + dRetail + dPrice + sInventory + dNo + cz + "</tr>").appendTo("#ShowSj");        });    });}

C#后台代码
C# code
public partial class ApplicationProcessing_Home : System.Web.UI.Page{    protected void Page_Load(object sender, EventArgs e)    {        if (!IsPostBack)        {             Response.ContentType = "text/plain";             TBL_BrandManager brandManager = new TBL_BrandManager();             Response.Write(brandManager.ShowBrand());        }    }}//实体类转换json数据    public class JsonHeleper    {        public string ObhestToJson<T>(T instance)        {            string result = string.Empty;            DataContractJsonSerializer json = new DataContractJsonSerializer(typeof(T));            MemoryStream ms = new MemoryStream();            json.WriteObject(ms, instance);            ms.Position = 0;            StreamReader sr = new StreamReader(ms);            result = sr.ReadToEnd();            return result;        }    }}


------解决方案--------------------------------------------------------
Response.ContentType = "text/plain";
TBL_BrandManager brandManager = new TBL_BrandManager();
Response.Write(brandManager.ShowBrand());

改成
Response.Clear();
Response.ContentType = "application/json";
TBL_BrandManager brandManager = new TBL_BrandManager();
Response.Write(brandManager.ShowBrand());
Response.End();

另外确保你返回的是真正的json格式
------解决方案--------------------------------------------------------
无法加载是什么意思?404错误?那就是url写错了

$.getJSON("<%=Page.ResolveUrl("~")%>ApplicationProcessing/ShowAllCommodity.aspx?nocache="+(new Date()).valueOf(), data, function (data)
  相关解决方案