1

所以我有一个网站,允许用户输入链接,然后提取信息并将其放入列表中。

现在一切正常,直到昨天我的网络托管合作伙伴进行了一些升级。我知道 mysql & php 一直在升级,但不知道还有什么。

首先,我遇到了无法登录数据库的问题(必须删除并重新创建用户)。然后是 JSON 的 PHP 序列化问题(需要更改代码)。然后是 412 无效的前置条件错误(需要托管合作伙伴设置的特殊规则)。现在最后一个 jquery 脚本已经停止工作。但我不知道为什么。它以前有效,但也许那是运气(我在这方面没有那么经验)。

无论如何,发生的事情是

  1. 用户输入链接。
  2. jquery 调用返回 JSON 的链接。
  3. 解析 JSON 并使用结果更新网页。
  4. 用户单击保存并将数据输入到数据库中。

使用 firebug 并在我的 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 是有效的(通过 firebug 并手动调用链接)并且 alert('inside') & alert('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/ajax.php?link=%22http://www.amazon.co.uk/LEGO-Star-Wars-9489-Imperial/dp/B005KISGAI/ref=pd_rhf_gw_shvl1%22&listid=41&memberid =24

可以在此处找到工作演示(根据要求); http://www.wishindex.com/test_newitem.php?listid=41

去测试;

  1. 在链接字段中输入来自 amazon.co.uk 的产品链接,例如 http://www.amazon.co.uk/LEGO-Star-Wars-9489-Imperial/dp/B005KISGAI/ref=pd_rhf_gw_shvl1
  2. 单击获取详细信息,其余字段应自动填充,但它们不是。
4

1 回答 1

1

您的 json 是数组中的一个对象。所以你应该只能像这样访问数据:result[0]['Itemname']或者result = result[0]在你访问它之前做。

所以它到达'inside2',因为result['Itemname']undefined!= ""

于 2012-08-03T08:19:00.817 回答