java jsonp

来源:互联网 发布:网络钵钵鸡什么意思 编辑:程序博客网 时间:2024/05/17 08:49

java 后台程序:

@Controller
public class TaskDetailController {


@ResponseBody
@RequestMapping(value = "/test.json", produces = "text/html;charset=UTF-8")
public String getTaskDetailByTaskId(String testId, HttpServletRequest request){

String callback = request.getParameter("callback");
if(null != callback){
String resultJsonp = callback + "(" + jsonObject.toString() + ")";
return resultJsonp;
}else{
return jsonObject.toString();
}

}

}

前端程序调用代码:

ur3 = "http://ip:8080/balantflow/module/sf/test.json"


         $.ajax({  
             type: "get",  
             //async: false,  
             url:ur3,  
data: "testId=123",
             dataType:"jsonp",  
jsonp:"callback",
             success:function(json){  
                 alert(json);  
             },  
             error: function(){  
                 alert('fail');  
             }  
         });  


原创粉丝点击