2017-10-04 15 views
-4

を定義した変数を認識していない私は私がタグに変数をロードしようとした「タイトル」 var title = result.title; 次の変数を定義して、次にJavaScriptでGET要求を送信し、その結果 var result = JSON.parse(response); を構文解析id = "fishplanet-title" しかし、HTMLは "title"が定義されていないと言うエラーを出しました。 コンソールにログを記録しているため、リクエストが処理されていることがわかります。HTMLは<script>タグに

HERESに要求: https://hastebin.com/eloqojimit.js

相続人の応答:相続人 https://hastebin.com/vinadafelo.json

エラー:Uncaught ReferenceError: title is not defined at user.html:178

+2

具体的にしてください。コードの投稿:リクエストの作成方法、発生したエラー、例外の発生、実際の "レスポンス"十分な情報を提供していないと、私たちはお手伝いできません。 –

+0

あなたの質問に[ask]と[edit](https://stackoverflow.com/posts/46573858/edit)を確認し、問題を示す[mcve]を含めてください。 – jmoerdyk

答えて

1

result.title が動作しません。

var title = JSON.parse(result).appnews.newsitems[0].title;

titleプロパティを取得するには

{ 
    "appnews": { 
     "appid": 380600, 
     "newsitems": [ 
      { 
       "gid": "2175660043472720797", 
       "title": "QuestionsAnswers", 
       "url": "http://store.steampowered.com/news/externalpost/steam_community_announcements/2175660043472720797", 
       "is_external_url": true, 
       "author": "Olcha", 
       "contents": "1.\"What is the garage icon for at the bottom of the Inventory page? Will this be for boat access and when can we expect boats to be launched?\" That’s right - the Garage will soon be the place from where you can access Boats. That’s exactly what we are currently working hard on and we plan to release this feature in the nearest future. Actually, we’ll share a video with you guys next week! Make sure to keep track of our news - it’ll be fun! 2. \"Will we see traditional carp fishing features such a...", 
       "feedlabel": "Community Announcements", 
       "date": 1506799022, 
       "feedname": "steam_community_announcements", 
       "feed_type": 1, 
       "appid": 380600 
      } 
     ] 
     , 
     "count": 277 
    } 
} 

、あなたはこのような何かをする必要があります:titleプロパティは、title値を得るためにそれを反復処理する必要があるので、アレイ内にあります

newsitemsは配列なので、1つ以上の配列を返す場合はiteratingを行う必要があります。