jsonp jquery jersey 实现跨域访问

前端之家收集整理的这篇文章主要介绍了jsonp jquery jersey 实现跨域访问前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

链接http://www.jb51.cc/article/p-orgsugoi-ra.html

服务器端:

[java] view plain copy
  1. @GET
  2. @Path("addTaskRest")
  3. @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
  4. @Produces(MediaType.TEXT_PLAIN)
  5. publicStringaddTaskRest(@QueryParam("data")Stringdata,@QueryParam("jsonpcallback")Stringjsonpcallback){
  6. System.out.println("data="+data);
  7. System.out.println("jsonpcallback="+jsonpcallback);
  8. Stringresult="";
  9. result=this.controller.addTask(data);
  10. returnjsonpcallback+"({\"id\":\""+result+"\"})";
  11. }
客户端:
[javascript]
    $.ajax({
  1. //url:"/portal/constructionNotice/showLineInfo.action?random="+Math.random(),
  2. url:"http://10.1.14.20:8088/workflowController/service/todo/addTaskRest",
  3. type:"get",
  4. jsonp:'jsonpcallback',248)"> data:{
  5. "data":"{\"app\":\"zhoushuntest\",\"type\":0,"
  6. +"\"occurTime\":\"2013-11-1411:22:02\",\"title\":\"-------流程标题-------\","
  7. +"\"loginName\":\"ST/G01008000311\",\"status\":0,\"removed\":0,248)"> +"\"typename\":\"流程名称11\",108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> +"\"url\":\"流程名称11\",248)"> +"\"pname\":\"主流程名称\",\"pincident\":1,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> +"\"cname\":\"子流程实例号\",\"cincident\":1,248)"> +"\"stepName\":\"当前步骤\",108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> +"\"initiator\":\"ST/G01008000311\"}"
  8. },
  9. dataType:"jsonp",//跨域必须用jsonp
  10. cache:false,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> error:function(XMLHttpRequest,textStatus,errorThrown){
  11. alert(XMLHttpRequest.status);
  12. alert(XMLHttpRequest.readyState);
  13. alert(textStatus);
  14. },
  15. success:function(obj){
  16. alert(obj.id);
  17. }
  18. });

猜你在找的Json相关文章