简体   繁体   English

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

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

I am trying to connect a Java REST service to a ExtJs JSONP request but even though the java method executes I haven't been able to get a response test. 我正在尝试将Java REST服务连接到ExtJs JSONP请求,但是即使执行了Java方法,我也无法获得响应测试。 This is what I am trying: 这是我正在尝试的:

Java Code: 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 code: 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);
            }
        }
    });

response is printting true, everything else undefined :( 响应打印为真,其他所有未定义:(

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

Any ideas what could be wrong? 任何想法可能有什么问题吗?

Ok this worked out for me: 好的,这对我有用:

    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.

相关问题 无法在Ajax中使用数据类型:“ jsonp”获得Java响应,但数据类型:“文本”有效 - Unable to get Java Response in Ajax with dataType: “jsonp” but dataType: “text” Works 如何从Java控制器中的Ext.Ajax.request获取参数 - How to get Parameter from Ext.Ajax.request in java controller Get 请求适用于 POSTMAN 但在我的 Java 应用程序中引发垃圾响应 - Get request works with POSTMAN but throws garbage response in my Java application 我正在从javascript函数对后端进行JSONP调用,以获取json中的响应数据。 从Java端如何做到这一点? - I am doing a JSONP call to backend from javascript function in order to get the response data in json. How to do this from java end? Http 请求从其他 web 应用程序获得响应 - Http request to get response from other web application 获取JSONP请求来自安全性的域名 - Get Domain Name That a JSONP Request is Coming From For Security 在java中获取请求和响应的数量 - Get number of Request and response in java 如何逐行读取文件并使用带有jsonp的java和ajax发送对ajax请求的响应? - How to read file line by line and send response to ajax request using java and ajax with jsonp? 从Plain Java应用程序调用JSP并获得响应 - Call JSP from Plain Java application and get response back to it 从Ext JS到Java的请求传输期间数据已更改 - Data changed during request transfer from Ext JS to Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM