Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/469.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用enter键ajaxapi提交JQuery表单_Javascript_Php_Jquery_Mysql_Ajax - Fatal编程技术网

Javascript 使用enter键ajaxapi提交JQuery表单

Javascript 使用enter键ajaxapi提交JQuery表单,javascript,php,jquery,mysql,ajax,Javascript,Php,Jquery,Mysql,Ajax,我尝试过各种解决方案,但没有一种适合我的特殊情况! 我如何使其在用户按下“回车”键时提交和搜索表单。 我还想尝试从HTML文档中删除JavaScript,并将其移动到ajax.js文档并选择它。 我不确定这样做的语法是否正确。 顺便说一下,我正在使用烂番茄API和AJAX search.php ajax.js 或者,您可以在filmlist函数的末尾返回false。您可以在inputbox元素中检测到带有以下jQuery代码的enter键按下: $('#inputbox').keyup(func

我尝试过各种解决方案,但没有一种适合我的特殊情况! 我如何使其在用户按下“回车”键时提交和搜索表单。 我还想尝试从HTML文档中删除JavaScript,并将其移动到ajax.js文档并选择它。 我不确定这样做的语法是否正确。 顺便说一下,我正在使用烂番茄API和AJAX

search.php

ajax.js


或者,您可以在filmlist函数的末尾返回false。

您可以在inputbox元素中检测到带有以下jQuery代码的enter键按下:

$('#inputbox').keyup(function(e) 
{
    if(e.keyCode == 13) 
    {
        //do your stuff
    }
});
您还可以使用$'inputbox'。更改为在用户键入时直接加载电影


不要忘记,一些旧的或移动浏览器不支持JavaScript。始终构建一个服务器端解决方案作为后备方案。

从HTML文档中删除JavaScript并将其移动到ajax.js文档并选择它是什么意思?
function filmlist (form) {
$('#films table').empty(); //removes previous search results before adding the new ones.

var apikey = "frceg2d5djxezaedgm3qq94h";
var baseUrl = "http://api.rottentomatoes.com/api/public/v1.0";
var moviesSearchUrl = baseUrl + '/movies.json?apikey=' + apikey;
var query = form.inputbox.value;  //uses the value from the input box as the query search



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


// 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>');
 });
}
}
$("form").submit(function(){
    $.ajax({
        url: moviesSearchUrl + '&q=' + encodeURI(query),
        dataType: "jsonp",
        success: searchCallback
    });
    return false;
});
$('#inputbox').keyup(function(e) 
{
    if(e.keyCode == 13) 
    {
        //do your stuff
    }
});