你好,我一直在尝试向JSP页面发起ajax请求。以下是JS函数的片段:
<script>
$(function(){
function myAjaxCall() {
$.ajax({
type: "post",
url: "jsp/common/myJavascriptPage.jsp",
dataType: "text",
success:
function (result) {
alert("Got the result: " + result);
},
error: function (xhr,status,error) {
alert("Status: " + status);
alert("Error: " + error);
alert("xhr: " + xhr.readyState);
},
statusCode: {
404: function() {
alert("page not found");
}
}
});
}
});
</script>
我不断收到“文件未找到”的提示,即使JSP在URL中存在。请注意,我正在相对于webapp目录计算JSP文件位置。
我尝试使用普通的AJAX调用(没有jQuery),但结果仍然是相同的错误。
能否请您帮助我理解为什么无法定位jsp文件?
url
更改为"/jsp/common/myJavascriptPage.jsp"
? - MilkyWayJoeresponse.getWriter().println(myResponse);
。 - Leo