我的问题是,如何从子目录中的页面发出ajax请求并获得响应。
在这里,我的页面index.jsp
被放置在子目录/vf2
内,其中包含了脚本文件
<script src="../script/testscript.js"></script>
function getPlaceFromIP3(){
var ipAdd="1";
var params ="ipAdd="+ipAdd;
var resultStringX = $.ajax({
type: "GET",
url:"result_page.jsp",
data: params,
async: false
}).responseText;
alert(resultStringX);
}
页面result_page.jsp
包含在public_html
目录中。
当我从index.jsp
调用函数时,我收到了一个找不到页面的消息。我如何从子目录向主目录中的页面发送请求。
答案 0 :(得分:1)
如果它是一个普通链接,你会如何链接到它?这同样适用于此。使用适当的文件相对URL。从根目录启动URL。
如果文件位于http://www.example.com/result_page.jsp
,则为
url:"/result_page.jsp",