lihui0234
V2EX  ›  Java

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

  •  
  •   lihui0234 · Jun 1, 2016 · 3138 views
    This topic created in 3812 days ago, the information mentioned may be changed or developed.

    //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 replies  •  2016-06-12 10:11:09 +08:00
    ooTwToo
    ooTwToo
    Jun 1, 2016 via iPhone
    1
    struts ?
    lihui0234
    lihui0234
    OP
    Jun 1, 2016
    2
    嗯嗯 structs2
    wkan
    wkan
    Jun 1, 2016 via iPhone
    3
    @lihui0234 是 struts 啦,话说 struct 返回 json 不应该是弄个 map 么,怎么直接就 string 了
    lihui0234
    lihui0234
    OP
    Jun 1, 2016
    4
    @wkan 返回 json 格式字符串
    wwqgtxx
    wwqgtxx
    Jun 1, 2016 via Android
    5
    为啥不用 struts2 的 json 插件来自动返回 json ?
    raptium
    raptium
    Jun 1, 2016 via iPhone
    6
    看起来是搞了个 jsonp 的返回,但是没有 callback 名字……
    thinkmore
    thinkmore
    Jun 12, 2016
    7
    response.write(jsonStr);
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1490 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 09:53 · PVG 17:53 · LAX 01:53 · JFK 04:53
    ♥ Do have faith in what you're doing.