我正在尝试通过JQuery创建一个AJAX请求 以下是我的代码。
但是当我通过Mozilla Firebug进行调试时,我观察到,没有请求命中服务器。
有人可以告诉我我在哪里做错了。
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JQuery Example</title>
</head>
<body>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$.ajax({
url: 'ajax/balances',
processData: false,
timeout: 10000,
type: "POST",
contentType: "application/xml",
dataType: "json",
data: '<MyReq user="' + User + '" katha="' + ivalitiKatha + '" />',
success: function(data) {
},
error : function() {
alert("Sorry, The requested property could not be found.");
}
});
});
</script>
</body>
</html>
这是我服务器端的web.xml
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/ajax/*</url-pattern>
</servlet-mapping>
答案 0 :(得分:1)
也许将<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
添加到头部而不是身体帮助!
答案 1 :(得分:0)
首先,我建议将CDN JQuery移到网站的主题部分。
其次,我测试了上面的代码,问题看起来就是你在JSON / AJAX请求中发布的(数据)。
如果删除它或修改为JSON,请求将返回一个结果,例如
$.ajax({
url: 'test',
processData: false,
timeout: 10000,
type: "POST",
contentType: "application/json",
dataType: "json",
data: '{"foo": "bar"}',
success: function(data) {
alert('Success');
},
error : function() {
alert("Sorry, The requested property could not be found.");
}
});
您需要将数据格式化为JSON请求
data: '{"foo": "bar"}',
希望这有帮助