【问题标题】:Jquery Ajax get url 400 (Bad Request)Jquery Ajax 获取 url 400(错误请求)
【发布时间】:2016-10-27 05:39:22
【问题描述】:

当我尝试从 url 获取信息时收到 400 bad request 错误。这是我的代码:

<script src="http://code.jquery.com/jquery-3.1.1.js"></script>

function searchData()
{
    dname = document.getElementById('dataname').value;

    $.ajax({
                type: "GET",
                url: "http://demo.ckan.org/api/3/action/package_search?q=" + dname,
                dataType: "jsonp",
                contentType:"application/json",
                headers: { "Authorization": "123456789123456" },
                error:function(e){
                    console.log(e);
                },
                success: function (data) {
                    var name = "<ul id='list'>";

                        if (data.length !== 0) {

                            for (var j = 0; j < data.length; j++) {
                                name += "<li>"+(j+1)+":"+ data[j] +">" ;
                            }
                        }
                        else {
                            name = "Sorry, there is no data";
                        }

                    name += "</ul><hr>";


                    $('#result').append(name);
                }
            });

        return false;

}

我得到了:

我通过谷歌浏览器尝试了http://demo.ckan.org/api/3/action/package_search?q=air,它给了我很好的结果,所以不是url的问题。

有人有什么想法吗?? 非常感谢。

【问题讨论】:

    标签: jquery json ajax url


    【解决方案1】:

    实际上问题是CKAN api不支持像jquery那样禁用缓存。所以我必须设置缓存:true

    感谢布赖恩的想法=> AJAX call error - status of 400 (Bad Request)

    【讨论】:

      猜你喜欢
      • 2013-04-07
      • 1970-01-01
      • 2020-04-23
      • 1970-01-01
      • 2019-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多