因此,我有一個網站,允許用戶輸入鏈接,然後提取信息並將其放入列表中。爲什麼這個jquery腳本不工作?
現在一切都很好,直到昨天,當我的虛擬主機合作伙伴做了一些升級。我知道,MySQL & PHP已經升級,但我不知道還有什麼。
首先,我遇到了無法登錄數據庫的問題(必須刪除並重新創建用戶)。 然後PHP序列化JSON的問題(需要更改代碼)。 然後出現412無效的預處理錯誤(需要託管合作伙伴設置的特殊規則)。 現在,所有jQuery腳本的最後一個已停止工作。但我不知道爲什麼。它以前工作過,但也許這是運氣(我沒有這麼經驗)。
總之,什麼情況是
- 用戶輸入的鏈接。
- jquery調用返回JSON的鏈接。
- 解析JSON並更新網頁並顯示結果。
- 用戶點擊保存並將數據輸入到數據庫中。
使用螢火蟲和將警報放在我的JavaScript然後我可以看到,步驟1,步驟2工作正常。返回的JSON是有效的(我已經使用JSONlint進行了驗證),但步驟3不起作用。我的腳本在下面;
function getURLData(form)
{
var listid = $('input#listid').val();
var memberid = $('input#memberid').val();
var link = $('input#link').val();
var sendstr = "http://www.wishindex.com/ajax.php?link=\"" + link + "\"&listid=" + listid + "&memberid=" + memberid;
alert(sendstr);
$.getJSON(sendstr,function(result)
{
alert('inside');
if(result['Itemname'] != "")
{
alert('inside2');
$('#itemname').val(result['Itemname']);
$('#itemname').attr('readonly', 'true');
$('#desc').val(result['Description']);
$('#category').val(result['Category']);
$('#category').attr('readonly', 'true');
$('#price').val(result['Price']);
$('#price').attr('readonly', 'true');
$('#choosepicture').attr('onclick', 'window.open(\'http://www.wishindex.com/picture.php?link=' + result['Link'] + '\')');
if (result['PictureLink'] != "")
{
$('#picturelink').val(result['PictureLink']);
$('#picturelink').attr('readonly', 'true');
}
else
$('#choosepicture').removeAttr('disabled');
$('#automatic').attr('value', 'true');
$('#currency').val(result['Currency']);
$('#currency').attr('readonly', 'true');
}
else
{
$('#automatic').attr('value', 'false');
$('#manual').html('Please enter details manually');
$('#choosepicture').removeAttr('disabled');
$('#choosepicture').attr('onclick', 'window.open(\'http://www.wishindex.com/picture.php?link=' + result['Link'] + '\')');
}
});
}
如果啓用了警報,然後我看到一個叫做鏈接是正確的,JSON是有效的(通過螢火併手動調用鏈接),該警示(「內部」)&警報('inside2 ')被執行,所以它到達了這段代碼,但我的html元素沒有更新!
正如我所說,在升級之前它很好,但也許我做錯了什麼,所以任何幫助將不勝感激,因爲我花了幾個小時,並找不到問題。
我的JSON響應;
[{"ID":"","MemberID":"24","Listid":"41","Itemname":"LEGO Star Wars 9489: Endor Rebel Trooper and Imperial Trooper","Description":null,"NumberDesired":null,"NumberPurchased":null,"Category":{"0":"TOYS_AND_GAMES"},"Link":"\"http:\/\/www.amazon.co.uk\/LEGO-Star-Wars-9489-Imperial\/dp\/B005KISGAI\/ref=pd_rhf_gw_shvl1\"","PictureLink":{"0":"http:\/\/ecx.images-amazon.com\/images\/I\/51fQnt%2BlppL._SL160_.jpg"},"Price":"9.89","Currency":"\u00a3","Priority":null,"SuggestedPurchaser":null,"ActualPurchaser":null,"PurchaseStatus":null,"Productid":"B005KISGAI","Site":"amazon.co.uk","DateAdded":null,"DatePurchased":null,"Domain":null,"Temp":["LEGO-Star-Wars-9489-Imperial","dp","B005KISGAI","ref=pd_rhf_gw_shvl1\""],"Error":"","Warning":null}]
您可以致電此獲得JSON結果例子
一個工作演示(的要求)可以在這裏找到; http://www.wishindex.com/test_newitem.php?listid=41
要測試;
- 從amazon.co.uk如 http://www.amazon.co.uk/LEGO-Star-Wars-9489-Imperial/dp/B005KISGAI/ref=pd_rhf_gw_shvl1 輸入商品鏈接到鏈接字段
- 點擊獲取細節和其餘字段應自動填充 ,而T3嘿嘿不是。
可以告訴你它的JSON或部分? – Andy 2012-08-03 08:05:23
我認爲你應該發佈一個現場演示。您的託管合作伙伴已完成更新。好。但如果Ajax調用的json結果是好的,那麼服務器端就沒問題。如果客戶昨天工作,那麼客戶就可以。所以......至少有一個你的假設是錯誤的:) – 2012-08-03 08:07:47