2016-05-08 45 views
0
<script type="text/javascript"> 
$(function(){ 
    //按鈕單擊時執行 
    alert("begin...."); 
    $("#testAjax").click(function(){ 
     $.ajax({ 
      type: "POST", 
      url: "http://XXXXXXX:8080/iswustserver/iswust/user/queryUserList", 
      data: {"page_num":"1"}, 
      dataType:"json", 
      contentType:'application/json;charset=utf-8', 
      success: function (data) { alert("1") }, 
      error: function (data) { console.log(data)} 
     }); 
    }); 
}); 

我嘗試使用我的本地的js文件來獲得遠程IP的數據,但它不工作

我的服務器:

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { 
     HttpServletResponse response = (HttpServletResponse) res; 
     response.setHeader("Access-Control-Allow-Origin", "*"); 
     response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE"); 
     response.setHeader("Access-Control-Max-Age", "3600"); 
     response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); 
     chain.doFilter(req, res); 
     } 

我用我的本地js文件,請求遠程IP獲取數據,但它返回400 錯誤的請求....

回答

0

我知道這聽起來滑稽,如果它的工作原理hoorah如果它不那麼我們將看看在替代:

嘗試將您的類型更改爲方法

$.ajax({ 
      method: "POST", // <--change here 
      url: "http://XXXXXXX:8080/iswustserver/iswust/user/queryUserList", 
      data: {"page_num":"1"}, 
      dataType:"json", 
      contentType:'application/json;charset=utf-8', 
      success: function (data) { alert("1") }, 
      error: function (data) { console.log(data)} 
     }); 
+0

仍然不好請求..... 400 –

+0

您可以添加您發佈數據的方法的代碼嗎?這是一個API嗎?有沒有某種配置URI? – ThatAwesomeCoder

相關問題