繁体   English   中英

从Ext / Java应用程序中的JSONP请求获取响应文本

[英]Get response text from a JSONP request in Ext / Java Application

我正在尝试将Java REST服务连接到ExtJs JSONP请求,但是即使执行了Java方法,我也无法获得响应测试。 这是我正在尝试的:

Java代码:

@Path("/hello")
public class Hello {

      @GET
      @Produces("text/javascript") // have also tried application/json
      public String sayJsonHello(@QueryParam("_dc") String dcIdentifier, @QueryParam("callback") String callback) {
          System.out.println(callback);
          callback += "({\"success\":true, \"msj\":" + "\"" + "Exitoooo!" + "\" });";
          System.out.println(callback);
        return callback;
      }

}

ExtJs代码:

    Ext.data.JsonP.request({
        url: "http://10.1.50.66:7001/Simulador/webresources/hello",
        params: {
        },
        callback: function (response) {
            console.log(response); //true
            console.log(response.result); //undefined
            console.log(response.responseText); //undefined
            console.log(response.success); // undefined
            if (response.success === true) {
                Ext.Msg.alert('Link Shortened', response.msj, Ext.emptyFn);
            } else { // entering here :( why ?
                Ext.Msg.alert('Error', response.msj, Ext.emptyFn);
            }
        }
    });

响应打印为真,其他所有未定义:(

回调看起来像这样Ext.data.JsonP.callback1({"success":true, "msj":"exito"})

任何想法可能有什么问题吗?

好的,这对我有用:

    Ext.data.JsonP.request({
        url: "http://10.1.50.66:7001/Simulador/webresources/hello",
        callbackKey: 'callback1',
        params: {
        },
        success : function(response) {
            console.log("Spiffing, everything worked");
            // success property
            console.log(response.success);
            // result property
            console.log(response.result);
            console.log(response.msj);
         },
         failure: function(response) {
              console.log(response);
              Ext.Msg.alert('Error', 'Please try again.', Ext.emptyFn);
          }
    });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM