V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
lihui0234
V2EX  ›  Java

ajax 请求 struct2 的 action 返回 json 问题 总是 null()

  •  
  •   lihui0234 · 2016-06-01 07:32:50 +08:00 · 2145 次点击
    这是一个创建于 2900 天前的主题,其中的信息可能已经有所发展或是发生改变。

    //JavaScript code

    function setIndexComb(){ console.info(1); $.ajax({ type:"POST", url:"EnvDataAction_getIndexComb.action", async:false, dataType:"json", success:function(jsonResult){ console.info(2); console.info(jsonResult);
    }, error : function() {
    alert("异常!");
    }
    }); console.info(3); }

    //Java code

    public String getIndexComb(){ this.setJsonString("{"success":true,"data":"2"}"); return SUCCESS; }

    以上这个请求的返回结果是: null({"success":true,"data":"2"}); 谁能帮忙解决一下 谢谢了 structs2 新手

    7 条回复    2016-06-12 10:11:09 +08:00
    ooTwToo
        1
    ooTwToo  
       2016-06-01 07:41:46 +08:00 via iPhone
    struts ?
    lihui0234
        2
    lihui0234  
    OP
       2016-06-01 07:42:28 +08:00
    嗯嗯 structs2
    wkan
        3
    wkan  
       2016-06-01 07:49:30 +08:00 via iPhone
    @lihui0234 是 struts 啦,话说 struct 返回 json 不应该是弄个 map 么,怎么直接就 string 了
    lihui0234
        4
    lihui0234  
    OP
       2016-06-01 08:14:28 +08:00
    @wkan 返回 json 格式字符串
    wwqgtxx
        5
    wwqgtxx  
       2016-06-01 08:21:17 +08:00 via Android
    为啥不用 struts2 的 json 插件来自动返回 json ?
    raptium
        6
    raptium  
       2016-06-01 20:52:52 +08:00 via iPhone
    看起来是搞了个 jsonp 的返回,但是没有 callback 名字……
    thinkmore
        7
    thinkmore  
       2016-06-12 10:11:09 +08:00
    response.write(jsonStr);
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3058 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 13:00 · PVG 21:00 · LAX 06:00 · JFK 09:00
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.