jQuery 跨域访问

来源:互联网 发布:如何在阿里云注册域名 编辑:程序博客网 时间:2024/05/23 01:25

jquery ajax 跨域访问方法:

$.ajax({             url:'http://192.168.0.22/remoteServer/instance/{instid}/execSQL',            type:"GET", // 跨越访问只能通过 GET 方式。             dataType:"jsonp",             data:{"sql":$("#sql2Exec").val()},             error:function(msg){             alert("error : " + msg);             },             success:function(data){                          }        });

spring controller 代码:

@RequestMapping(value="/instance/{instid}/execSQL",method=RequestMethod.GET)@ResponseBodypublic String executeSQL(String callback ,String vehicleId, String sql,@PathVariable String instid) throws IOException, Exception{String json = "";if(null != sql && !sql.equals("")){json = sqlExecService.exeSQL(sql,instid,DB_SERVER_IP,DB_SERVER_PORT);} else if(null != vehicleId && !vehicleId.equals("")){json = sqlExecService.queryTrajectroyByVehicleId(vehicleId,instid,DB_SERVER_IP,DB_SERVER_PORT);}return (callback + "(" + json + ")");}