【发布时间】:2014-11-12 14:13:02
【问题描述】:
您好,我一直在尝试对 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>
我经常找不到文件,即使提到的 URL 中存在 JSP。请注意,我正在计算相对于 webapp 目录的 JSP 文件位置。
我尝试使用普通的 AJAX 调用(不使用 jQuery),但最终出现同样的错误。
能否请您帮我理解为什么它无法找到 jsp?
【问题讨论】:
-
首先,jsp/common/myJavascriptPage.jsp 返回什么?
-
您可以尝试在通话中将
url更改为"/jsp/common/myJavascriptPage.jsp"吗? -
我只是返回一段文字。它嵌入了一个java代码。我正在使用
response.getWriter().println(myResponse); -
@MilkyWayJoe 刚试过。没用。
标签: javascript jquery ajax