Using $.each() within $.getJSON

This is for a jQuery Mobile app using version 1.0.1. I'm trying to get data from my `getmovies.php` file, which outputs JSON, to use in a jQuery function which appends the data to an unordered list on my HTML page. My HTML page displays correctly, but the getMoviesList() function does not append any list items, so the content area is left blank. My guess is that there is something wrong with my $.each() function. I'm more comfortable with PHP, but trying to get more familiar with jQuery and JSON for moving data around within jQuery Mobile apps. `getmovies.php` outputs **JSON** as follows: {"items":[ {"movieID":"65086","title":"The Woman in Black","poster":"\/kArMj2qsOnpxBCpSa3RQ0XemUiX.jpg"}, {"movieID":"76726","title":"Chronicle","poster":"\/853mMoSc5d6CH8uAV9Yq0iHfjor.jpg"} ]} My **Javascript** is as follows: var serviceURL = ""; var movies; $('#moviesPage').bind('pageinit', function(event) { getMoviesList(); }); function getMoviesList() { $.getJSON(serviceURL + 'getmovies.php', function(data) { $('#moviesList li').remove(); movies = data.items; $.each(movies, function(index, movie) { $('#moviesList').append('
  • ' + '' + '

    ' + movie.title + '

    ' + '

    Other details...

    ' + '
  • '); }); $('#movieList').listview('refresh'); }); } My **HTML** looks like this:
      I'm trying to modify the following example app to meet my needs: Thanks for any help you can offer.
      Do you get data when you run console.log(movie) on the first line of the each?

      以上就是Using $.each() within $.getJSON的详细内容,更多请关注web前端其它相关文章!

      赞(0) 打赏
      未经允许不得转载:web前端首页 » jQuery 答疑

      评论 抢沙发

      • 昵称 (必填)
      • 邮箱 (必填)
      • 网址

      前端开发相关广告投放 更专业 更精准