有谁知道为什么这不是让我的表格提交? jQuery错误

时间:2014-11-03 20:05:35

标签: javascript jquery html ajax

我试图让用户使用烂番茄API搜索电影,但无论我尝试什么,我似乎都遇到了麻烦。我是jquery的新手并且不断收到错误' Uncaught TypeError:undefined不是函数' jQuery代码的第二行。有谁知道解决方案?

这是代码..

HTML表单

<form name="myform" action="" method="GET"><h3>Search for a movie here:</h3><br> 
<input type="text" id="inputbox" value="">&nbsp;
<input type="submit" name="submit" value="Go!">

jQuery&amp;阿贾克斯      

 $(function(){

    $('form[name="myform"]').on('submit', function(e) {
        e.preventDefault();

        $('#films table').empty(); //removes previous search results before adding the new ones.

        var apikey = "MY API KEY";
        var baseUrl = "http://api.rottentomatoes.com/api/public/v1.0";
        var moviesSearchUrl = baseUrl + '/movies.json?apikey=' + apikey;
        var query = $('#inputbox').val(); //uses the value from the input box as the query search

        // sends the query
        $.ajax({
            url: moviesSearchUrl + '&q=' + encodeURI(query),
            dataType: "jsonp",
            success: searchCallback // if successful, run searchCallback function
        });

        // receives the results
        function searchCallback(data) {
            $('#films table').append('Found ' + data.total + ' results for ' + query);
            var movies = data.movies;
            $.each(movies, function(index, movie) {
                $('#films table').append('<tr><td width="70" rowspan="2"><a href="' + movie.links.alternate +
                '" title="Click here to view film information for ' + movie.title + '."><img class="ajaximage" src="'
                + movie.posters.thumbnail + '" /></a></td><td class="ajaxfilmlisttitle"><h3><a href="' + movie.links.alternate +
                '" title="Click here to view film information for ' + movie.title + '.">' + movie.title + '</a></h3>Release year: '
                + movie.year + '</td></tr><tr><td class="ajaxfilmlistinfo">Audience Score: ' + movie.ratings.audience_score +
                '%<br>' + 'Cinema Release Date: ' + movie.release_dates.theater +
                '<br>Runtime: ' + movie.runtime + ' minutes</td></tr>');
            });
        };
    });
});

0 个答案:

没有答案