javascript - JSONP not working with Jersey and JQuery -
i have restful server , jquery script calling data. not able data via jsonp.
java method:-
@get @path("search") @jsonp(queryparam="callback") @produces({"application/x-javascript"}) public response getalltestdata(@queryparam("callback") string callback) { system.out.println("i got executed!"); string result="{\"id\":1}"; //return response.status(200).entity("{ foo: 'bar' }").build(); //return result; return response.ok("{status: 'success'}").header("access-control-allow-origin", "*").build(); }
jquery script:-
$("button").click(function() { var surl = "http://localhost:8080/wikirating/engine/employee/search"; $.ajax({ type: 'get', url: surl, data: {"name": 1}, datatype: "jsonp", jsonp : "callback", jsonpcallback: "jsonpcallback", success: function(json) { alert("success"); }, error: function(e) { alert("error"); } }); });
i using apache tomcat v7.0
web.xml
<?xml version="1.0" encoding="utf-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="webapp_id" version="3.0"> <display-name>wikirating</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <filter> <filter-name>corsfilter</filter-name> <filter-class>org.apache.catalina.filters.corsfilter</filter-class> </filter> <filter-mapping> <filter-name>corsfilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <servlet> <servlet-name>jersey web application</servlet-name> <servlet-class>com.sun.jersey.spi.container.servlet.servletcontainer</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>jersey web application</servlet-name> <url-pattern>/engine/*</url-pattern> </servlet-mapping> </web-app>
i think have set headers does't seem work , error fired , alert("error");
executed.
also script running on port 80 while tomcat server running on port 8080 .
thanking in advance.
Comments
Post a Comment