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 錯誤的請求....
仍然不好請求..... 400 –
您可以添加您發佈數據的方法的代碼嗎?這是一個API嗎?有沒有某種配置URI? – ThatAwesomeCoder