2016-10-27 145 views
0

當我試圖從一個url獲取信息時,我得到了一個400錯誤的請求錯誤。這裏是我的代碼:Jquery Ajax get 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; 

} 

而且我得到了: enter image description here

我試圖通過http://demo.ckan.org/api/3/action/package_search?q=air谷歌Chrome和它給了我良好的效果,所以它不是URL的問題。

任何人有一些想法? 非常感謝。

回答