1

そのため、ユーザーがリンクを入力できるWebサイトがあり、情報を抽出してリストに配置します。

今、私のウェブホスティングパートナーがいくつかのアップグレードを行った昨日まで、すべてが正常に機能していました。mysqlとphpがアップグレードされていることは知っていますが、他に何があるかわかりません。

最初に、DBにログインできないという問題がありました(ユーザーを削除して再作成する必要がありました)。次に、JSONのPHPシリアル化に関する問題(コードの変更が必要)。次に、412の無効な前提条件エラー(ホスティングパートナーによって設定された特別なルールが必要)。そして最後に、jqueryスクリプトが機能しなくなりました。しかし、その理由はわかりません。以前は機能していましたが、運が良かったかもしれません(私はこれについてあまり経験がありません)。

とにかく、何が起こるか

  1. ユーザーがリンクを入力します。
  2. jqueryは、JSONを返すリンクを呼び出します。
  3. JSONが解析され、Webページが結果で更新されます。
  4. ユーザーが[保存]をクリックすると、データがDBに入力されます。

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. http://www.amazon.co.uk/LEGO-Star-Wars-9489-Imperial/dp/B005KISGAI/ref=pd_rhf_gw_shvl1などのamazon.co.ukからの商品リンクを リンクフィールドに入力します
  2. [詳細を取得]をクリックすると、残りのフィールドに自動的に入力されますが、そうではありません。
4

1 に答える 1

1

jsonは配列内のオブジェクトです。したがって、次のようなデータにのみアクセスできる必要があります。result[0]['Itemname']または、result = result[0]アクセスする前にアクセスできます。

つまり、「inside2」に到達result['Itemname']undefinedます。!= ""

于 2012-08-03T08:19:00.817 に答える