从子目录发出ajax请求

时间:2012-06-16 12:29:25

标签: javascript ajax jsp request

我的问题是,如何从子目录中的页面发出ajax请求并获得响应。  在这里,我的页面index.jsp被放置在子目录/vf2内,其中包含了脚本文件

<script src="../script/testscript.js"></script>

testscript.js

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调用函数时,我收到了一个找不到页面的消息。我如何从子目录向主目录中的页面发送请求。

1 个答案:

答案 0 :(得分:1)

如果它是一个普通链接,你会如何链接到它?这同样适用于此。使用适当的文件相对URL。从根目录启动URL。

如果文件位于http://www.example.com/result_page.jsp,则为

url:"/result_page.jsp",