AJAX在控制台日志中没有返回任何响应

时间:2018-01-02 01:01:20

标签: javascript jquery ajax api

我正在处理一个群组项目,我正在尝试让我的API在控制台日志中返回响应。我解决了任何错误,但是当我点击提交时,我根本没有得到任何回复。

的JavaScript

var zipcode = "";

function localMovieSearch() { 
    var queryURL = "http://data.tmsapi.com/v1.1/movies/showings?startDate=" + "2017-01-01" + "&zip=" + "75206" + "&api_key=guyv9by6h494tz4s9xfvpqrq";



    $.ajax({
        url: queryURL,
        method: "GET"
        }).done(function(response) {
            console.log(response);
        });
};


$("#movieZipSearch").on("click", function(event){
    localMovieSearch();
    zipcode = $("#movieZipInput").val().trim();
});

HTML

<div class="row">
    <div class="col s12 m12 l6 xl6">
        <div class="panel-boxes">
           <div class="panel-heading">SEARCH FOR LOCAL MOVIES NOW PLAYING</div>
              <div class="panel-body">
                    <div class="form-group">
                        <input type="text" class="form-control" id="movieZipInput">
                        <button type="search" class="btn" id="movieZipSearch" style="margin-right: 20px; margin-left: 15px">Search</button>
                    </div>  
                    <div class="panel-body recipesContainer" id="movieZipOutput" ></div>    
              </div>
            </div>
        </div>

1 个答案:

答案 0 :(得分:1)

根据the documentation pagesample code API /movies/showings接受请求(我今天仅使用值更改了startDate参数):

<script type='text/javascript'>
    var zipcode = "";
    function localMovieSearch() { 
        var queryURL = "http://data.tmsapi.com/v1.1/movies/showings?startDate=" + "2018-01-02" + "&zip=" + "75206" + "&api_key=guyv9by6h494tz4s9xfvpqrq";

        $.ajax({
        url: queryURL,
        method: "GET",
        dataType: 'json'
        }).done(function(response) {
            console.log(response);
        }).fail(function(){
            console.log("error")
        });
    };
    $("#movieZipSearch").on("click", function(event){
        localMovieSearch();
        zipcode = $("#movieZipInput").val().trim();
    });
</script>

您的代码看起来不错。只需确保首先在http://developer.tmsapi.com/io-docs测试API请求。所以,你会得到答应。您的控制台没有打印任何内容,因为您发送的startDate参数可能在服务器上没有适当的数据,因为在这种情况下服务器也会发送状态代码200 OK