为什么Ajax没有从表中获取数据并显示它


Why is Ajax not getting the data from the table and displaying it?

我的Get函数是运行的PHP

`// retreive all the movies
    function movies_get() {
    $this->load->database();
    $sql = 'SELECT * FROM movies;';
    $query = $this->db->query($sql);
    $data = $query->result();
    $this->response($data, 200);
    }`

http://creative.coventry.ac.uk/~ 4078078/moviereviews/v1.0/index.php/电影/电影
在顶点我得到这个结果或这个链接:

`{
    "id": "1",
    "Title": "Anna Karenina",
    "Director": "Joe Wright",
    "cast": "Keira Knightley Jude Law Arron Taylor-Johnson",
    "genre": "Drama"
  },`

我正在尝试使用AJAX将电影的标题显示在#movies页面上。这是我的代码,但它不起作用,我真的无法找出错误,我是AJAX的新手,但我已经写了这个代码,错误是什么,可能是我要求显示标题,但它显示的不仅仅是标题吗?

function Get() {
        $.ajax({
            url: 'http://creative.coventry.ac.uk/~4078078/moviereviews/v1.0/index.php/movie/movies',
            dataType: 'json',
            success: function (data) {
                $.each(data.movie, function (i, id) {
                    $('#movies').append('<li> <a href="" data-transition="slide"   onclick="Getmovies(' + movies.id + ')">' + movies.Title + '<div class="ui-li-count">' + movies.records + '</div></a><li>');
                });
                $.mobile.changePage("#movies"); //show the results page
                $('#home').listview('refresh');
            },
            //error: function (response) {
            //var r = jQuery.parseJSON(response.responseText);
            //alert("Message: " + r.Message);
            //}
        }
        )
    };

AJAX返回的响应(url:http://creative.coventry.ac.uk/~4078078/moviereviews/v1.0/index.php/电影/电影)本身就是一个数组。所以,你应该迭代"data"而不是"data.movice"。你可以更新你的代码如下:

    $(data.movie).each(function(i,movie){
        $('#movies').append('<li> <a href="" data-transition="slide"   onclick="Getmovies('+movie.id+')">'+movie.Title+'<div class="ui-li-count">'+movie.records+'</div></a><li>');
    });