ajax调用geoServer rest接口实现数据发布
2018-03-21 16:15
429 查看
geoserver服务端配置见前述文章,这里把我实现的几段js代码记录备忘。
api文档见http://docs.geoserver.org/2.12.2/user/rest/index.html#rest
为方便测试,提前把认证配置文件rest.properties改了一下/**;POST,GET,PUT=IS_AUTHENTICATED_ANONYMOUSLY
/**;DELETE=ROLE_ADMINISTRATOR数据目录形式:工作区>数据存储>图层
创建工作区及发布服务时,返回结果会报类似于“parsererrorSyntaxError: Unexpected end of JSON input”这样的错误,还不清楚什么原因,但是不影响创建结果。
1、得到工作区
//get
$.ajax({
url: 'http://localhost:8080/geoserver/rest/workspaces',
dataType: 'json',
type: 'GET',
data:null,
success: function(data, textStatus){
//data可能是xmlDoc、jsonObj、html、text等等
console.log(data);
this; //调用本次ajax请求时传递的options参数
},
error:function(XMLHttpRequest, textStatus, errorThrown){
//通常情况下textStatus和errorThrown只有其中一个包含信息
console.log(textStatus+errorThrown);
this; //调用本次ajax请求时传递的options参数
}
})
2、新建工作区
$.ajax({
url: 'http://localhost:8080/geoserver/rest/workspaces',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
// async: false,
// processData:false,
data: JSON.stringify({"workspace":{"name":"test03"}}),
success: function(data, textStatus){
//data可能是xmlDoc、jsonObj、html、text等等
console.log(data);
this; //调用本次ajax请求时传递的options参数
},
error:function(XMLHttpRequest, textStatus, errorThrown){
//通常情况下textStatus和errorThrown只有其中一个包含信息
console.log(textStatus+errorThrown);
this; //调用本次ajax请求时传递的options参数
},
headers: {
'Authorization': 'Basic YWRtaW46Z2Vvc2VydmVy'
}
})
3、得到数据存储
$.ajax({
url: 'http://localhost:8080/geoserver/rest/workspaces/nyc/datastores',
dataType: 'json',
type: 'GET',
data:null,
success: function(data, textStatus){
//data可能是xmlDoc、jsonObj、html、text等等
console.log(data);
this; //调用本次ajax请求时传递的options参数
},
error:function(XMLHttpRequest, textStatus, errorThrown){
//通常情况下textStatus和errorThrown只有其中一个包含信息
console.log(textStatus+errorThrown);
this; //调用本次ajax请求时传递的options参数
}
})
4,上传发布压缩后的shp文件,如果需要可以创建数据存储
/*var formTest=document.getElementById("form1");
console.log(formTest);*/
var file=$('#uploadFile')[0].files[0];
var formData = new window.FormData();
formData.append('file', file);
$.ajax({
url: 'http://localhost:8080/geoserver/rest/workspaces/test01/datastores/test/file.shp',
dataType: 'json',
contentType:'application/zip',
processData: false,
type: 'PUT',
async: false,
data:formData,
success: function(data, textStatus){
//data可能是xmlDoc、jsonObj、html、text等等
console.log(data);
this; //调用本次ajax请求时传递的options参数
},
error:function(XMLHttpRequest, textStatus, errorThrown){
//通常情况下textStatus和errorThrown只有其中一个包含信息
console.log(textStatus+errorThrown);
this; //调用本次ajax请求时传递的options参数
}
})
参考文档http://blog.csdn.net/dahongdahong/article/details/54629407
api文档见http://docs.geoserver.org/2.12.2/user/rest/index.html#rest
为方便测试,提前把认证配置文件rest.properties改了一下/**;POST,GET,PUT=IS_AUTHENTICATED_ANONYMOUSLY
/**;DELETE=ROLE_ADMINISTRATOR数据目录形式:工作区>数据存储>图层
创建工作区及发布服务时,返回结果会报类似于“parsererrorSyntaxError: Unexpected end of JSON input”这样的错误,还不清楚什么原因,但是不影响创建结果。
1、得到工作区
//get
$.ajax({
url: 'http://localhost:8080/geoserver/rest/workspaces',
dataType: 'json',
type: 'GET',
data:null,
success: function(data, textStatus){
//data可能是xmlDoc、jsonObj、html、text等等
console.log(data);
this; //调用本次ajax请求时传递的options参数
},
error:function(XMLHttpRequest, textStatus, errorThrown){
//通常情况下textStatus和errorThrown只有其中一个包含信息
console.log(textStatus+errorThrown);
this; //调用本次ajax请求时传递的options参数
}
})
2、新建工作区
$.ajax({
url: 'http://localhost:8080/geoserver/rest/workspaces',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
// async: false,
// processData:false,
data: JSON.stringify({"workspace":{"name":"test03"}}),
success: function(data, textStatus){
//data可能是xmlDoc、jsonObj、html、text等等
console.log(data);
this; //调用本次ajax请求时传递的options参数
},
error:function(XMLHttpRequest, textStatus, errorThrown){
//通常情况下textStatus和errorThrown只有其中一个包含信息
console.log(textStatus+errorThrown);
this; //调用本次ajax请求时传递的options参数
},
headers: {
'Authorization': 'Basic YWRtaW46Z2Vvc2VydmVy'
}
})
3、得到数据存储
$.ajax({
url: 'http://localhost:8080/geoserver/rest/workspaces/nyc/datastores',
dataType: 'json',
type: 'GET',
data:null,
success: function(data, textStatus){
//data可能是xmlDoc、jsonObj、html、text等等
console.log(data);
this; //调用本次ajax请求时传递的options参数
},
error:function(XMLHttpRequest, textStatus, errorThrown){
//通常情况下textStatus和errorThrown只有其中一个包含信息
console.log(textStatus+errorThrown);
this; //调用本次ajax请求时传递的options参数
}
})
4,上传发布压缩后的shp文件,如果需要可以创建数据存储
/*var formTest=document.getElementById("form1");
console.log(formTest);*/
var file=$('#uploadFile')[0].files[0];
var formData = new window.FormData();
formData.append('file', file);
$.ajax({
url: 'http://localhost:8080/geoserver/rest/workspaces/test01/datastores/test/file.shp',
dataType: 'json',
contentType:'application/zip',
processData: false,
type: 'PUT',
async: false,
data:formData,
success: function(data, textStatus){
//data可能是xmlDoc、jsonObj、html、text等等
console.log(data);
this; //调用本次ajax请求时传递的options参数
},
error:function(XMLHttpRequest, textStatus, errorThrown){
//通常情况下textStatus和errorThrown只有其中一个包含信息
console.log(textStatus+errorThrown);
this; //调用本次ajax请求时传递的options参数
}
})
参考文档http://blog.csdn.net/dahongdahong/article/details/54629407
相关文章推荐
- ext实现ajax调用接口加数据到grilpanel
- asp.net 前端跟后端通过接口调用实现数据交互(含分页)
- jQuery+JSONP通过调用虾米接口实现类似点点网发布音乐的功能
- openlayer调用geoserver发布的地图实现地图的基本功能
- MVC4中AJAX Html页面打开调用后台方法实现动态加载数据库中的数据
- 调用REST接口获取数据
- 转换Arcgis Server REST接口实现OL2直接调用
- Ajax调用restful接口传送Json格式数据的方法
- spring整合cxf方式发布的rest webservice,调用接口
- Jersey+Spring 实现rest 接口 服务调用
- ajax跨域实现api 接口调用
- asp.net ajax客户端编程+jquery:实现泛型数据的客户端数据调用、添加、删除
- ajax传送json格式数据,调用restful接口
- jsp代理实现ajax跨域调用获取数据
- asp.net ajax客户端编程+jquery:实现泛型数据的客户端数据调用、添加、删除
- XMlHTTP ajax实现数据无刷新调用
- .net之Ajax获取接口数据并实现循环播放
- 发布Silverlight项目自动生成模板,自动生成Silverlight调用RIA Service实现数据增删查改
- 【CI学习笔记】利用jquery中的ajax,调用接口,实现登录
- Jersey+Spring 实现rest 接口 服务调用