【问题标题】:Ajax not getting proper URL from server path in jsp using struts 2Ajax没有使用struts 2从jsp中的服务器路径获取正确的URL
【发布时间】:2013-12-13 07:02:26
【问题描述】:

我在服务器路径中动态存储一些 JSON 文件并使用 struts 2 框架检索 JSON 数据。当请求 AJAX 调用以检索 JSON 时,我得到的 URL 路径为 www.mydomain.com:8080/mydomain.com/myserver/myjsonpath/jsonfile.json 而不是 http://www.mydomain.com/myserver/myjsonpath/jsonfile.json。我还想提一下,由于这个原因,我无法进入 AJAX 的成功字段。它总是进入错误字段。我是在 Firebug 的帮助下才知道这个 URL 的。

//My AJAX request

String img_path="www.mydomain.com/myserver/";
String json_url=img_path+"/myjsonpath";

$(document).ready(function(){
   alert("<%=json_url%>/jsonfile.json"); // here am getting correct URL path from server
   $.ajax({
           type: "get",
           url:"<%=json_url%>/jsonfile.json",
           dataType: "json",
           success:function(data){
                   alert(data);    // not entering here
           error:function (xhr, ajaxOptions, thrownError){
                   alert(xhr.status); // enters here
 }}); 

【问题讨论】:

    标签: jquery ajax json jsp struts2


    【解决方案1】:

    首先,使用 scriplets 根本不是一个好主意。

    有s:url标签和这里是如何使用它。

    $(document).ready(function(){
       alert("<s:url value="myserver/myjsonpath"/>/jsonfile.json");
    //...
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-15
      • 1970-01-01
      • 1970-01-01
      • 2021-12-15
      • 2021-06-07
      相关资源
      最近更新 更多