0
我已經查找了所有的答案,並且我沒有看到其中一個。getJSON回調不會因爲其中一個JSON元素中的URL而觸發
我與之合作的一點歷史。我從一臺服務器加載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具有無效字符。
有沒有什麼,我需要做的準備我的細節鏈接(URL)的JSON輸出?
在此先感謝。
這裏是我的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 "}"
控制檯在失敗時說什麼? – tymeJV
這個JSON格式不正確,因爲左邊有'{[{',但右邊用'}}]}'關閉',中間沒有'{'來平衡。 – Paul
就是這樣,它說200 OK。它正在加載數據,我可以使用DOM檢查器檢查它,但回調不是「回調」。 即使我嘗試console.log('Test');它不起作用。 –