【发布时间】:2017-05-31 13:36:45
【问题描述】:
我正在尝试使用 jquery 发送一个 ajax 获取请求,但我收到此错误:
未捕获的类型错误:非法调用 在 e (jquery.min.js:4) 在 dc (jquery.min.js:4) 在 dc (jquery.min.js:4) 在 Function.n.param (jquery.min.js:4) 在 Function.ajax (jquery.min.js:4) 在 home.js:2
var cid = document.getElementById("id").value;
$.ajax({
type : "GET",
url : windowLocationS + "findTourByCustomId",
data : {
id : cid
},
async : false,
cache : false,
dataType : "json",
contentType: "application/json",
success : function(jsn) {
console.log(jsn.length);
},
error : function(error) {
console.log(error);
}
});
控制器:
@RequestMapping(value= "/findTourByCustomId", method = RequestMethod.GET, headers = "Accept=application/json")
public List<classA> findTourByCustomId(@RequestParam(value = "id", required = true) String id) {
return service.findByCustomId(id);
}
如何才能成功获取数据?
【问题讨论】:
-
您在问题中放置的 js 代码 sn-p 是您的
home.js文件吗? -
@eeya 是的,sn-p 代码在
home.js -
如果可以,可以更新您的问题并向我们展示您如何包含您称为
jquery.js和home.js的<script>标签?