我很难搞清楚这一点 . 我想知道 TypeError 是否是由第二个AJAX调用(或 osmtogeojson.js )引起的?

我通过提醒它确保第一个成功函数中的数据不为空 .

function sendQueryData(url, query){
    url =url.replace('query' , query);

    if (query === ""){
        alert("City Input Required");
    }else{
        $.ajax({
          beforeSend: function(xhr, settings) {
            if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
                xhr.setRequestHeader("X-CSRFToken", csrftoken);
            }
          },
          type: "POST",
          url: "/search/pass/",
          data: {
              'query' : query
          },
          success: function(data){
             $.ajax({
                type: "POST",
                contentType: 'application/json;  charset=utf-8',
                dataType: 'json',
                url: url,
                data: {
                    'feature': osmtogeojson(data)
                },
                success: function (data) {
                    window.location.href = url
                }
            });
          }
        });
    }
}

这是浏览器控制台输出的内容:

TypeError:e.elements未定义[了解更多] osmtogeojson.js:4:2503 n http:// localhost:8000 / static / js / osmtogeojson.js:4:2503 u http:// localhost:8000 / static / js / osmtogeojson.js:4:14818成功http:// localhost:8000 /:235:36我https://ajax.googleapis.com/ajax/libs/jquery/3.2.1 /jquery.min.js:2 :28012 firewith https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js:2:28783一个https://ajax.googleapis.com/ajax/libs/jquery/3.2 .1 / jquery.min.js:4:14033 c / <https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js:4:16323