由于其中一个JSON元素中的URL,getJSON回调未触发

时间:2013-08-27 19:01:46

标签: jquery ajax json getjson jquery-callback

我已经到处寻找答案了,我没有看到答案。

我正在处理的一段历史。我从一台服务器加载XML,将其转换为我服务器上的JSON文件,因此我可以轻松使用它(使用JS)。

我的json看起来像这样:

{ "listings": [{ "detailsLink": "http://idx.firstidx.com/NewDetails.aspx?MLS=2529220&TableType=SingleFamily&DatabaseID=50&Domain=639 ", "detailsPrice": "149000", "detailsBeds": "0", "detailsBaths": "1", "detailsCity": "Floral Park", "detailsImage": "http://3pv.mlsstratus.com/mlsmultiphotos/full/1/220/2529220.jpg", "detailsState": "NY" }]}

我的jquery看起来像这样:

$.getJSON('get-json.asp', function(data){
    $.each(data.listings, function(i,l){
        var detailsLink     = l.detailsLink;
        var detailsImage    = l.detailsImage;
        var detailsPrice    = l.detailsPrice;
        var detailsBeds     = l.detailsBeds;
        var detailsBaths    = l.detailsBaths;
        var detailsCity     = l.detailsCity;
        var detailsState    = l.detailsState;

    // Here is where I plan to do magical things with my new variables.

    });
});

回调函数没有为我开火。当我从JSON文件中删除detailsLink时,它没有任何问题。 detailsImage不会导致错误。

我检查了我的JSON是否在线免费服务是否有效,如果我手动粘贴JSON,它会变得干净但是当我从URL加载它时,它会显示detailsLink的字符无效。< / p>

为JSON输出准备我的detailsLink(URL)是否需要做些什么?

提前致谢。

这是我的ASP文件的VB:

Set listings = xml.getElementsByTagName("PropertyDetails")
        Response.Write "{"
        Response.Write " ""listings"": ["
        For i = 0 to (listings.Length-1)

            Response.Write "{"

            Response.Write " ""detailsPrice"":" &  " """ & listings.item(i).childNodes(11).text &  """, "
            Response.Write " ""detailsLink"":" &  " """ & listings.item(i).childNodes(0).text &  """, "
            Response.Write " ""detailsBeds"":" &  " """ & listings.item(i).childNodes(8).text &  """, "
            Response.Write " ""detailsBaths"":" &  " """ & listings.item(i).childNodes(9).text &  """, "
            Response.Write " ""detailsCity"":" &  " """ & listings.item(i).childNodes(4).text &  """, "
            Response.Write " ""detailsImage"":" &  " """ & listings.item(i).childNodes(15).text &  """, "
            Response.Write " ""detailsState"":" &  " """ & listings.item(i).childNodes(6).text &  """ "

        if i < (listings.length-1) then 'If this is not the last listing add a comma after the curley brace

            Response.Write "},"
            else
             Response.Write "}" 'This is the last listing, so no comma
        end if
        Next
        Response.Write "]"
        Response.Write "}"

1 个答案:

答案 0 :(得分:1)

好的,在进一步研究之后,我可以看到我没有在网站正面看到我的Jquery读取任何JSON标题信息。

我没有用手写出来,而是决定使用一个可以在VB(ASP)端为我做这个的库。

我使用的课程位于:http://www.aspjson.com/

感谢你们的帮助。