lihui0234
V2EX  ›  Java

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

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