1. 程式人生 > >Ajax POST請求呼叫Geoserver的WFS服務

Ajax POST請求呼叫Geoserver的WFS服務

Ajax POST請求呼叫Geoserver的WFS服務

在使用jquery的POST呼叫Geoserver的WFS服務遇到的問題
1、Geoserverde的WFS服務傳入的引數是XML的String型別,Content-type為contentType:”text/plain;charset=UTF-8”,開始沒有注意到ajax的post請求的預設 contentType預設值: “application/x-www-form-urlencoded”。

<!DOCTYPE html>
<html>
<head lang="en">
    <meta
charset="UTF-8">
<script src="../lib/ol-debug.js"></script> <script src="../lib/jquery.min.js"></script> <link href="../lib/ol.css" rel="stylesheet"> <title></title> </head> <body> <button onclick="request()">請求</button> <script
type="text/javascript">
var string1 = "<GetFeature xmlns=\"http://www.opengis.net/wfs\" service=\"WFS\" version=\"1.1.0\" outputFormat=\"application/json\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd\"><Query typeName=\"osm:water_areas\" srsName=\"EPSG:3857\" xmlns:osm=\"http://openstreemap.org\"><Filter xmlns=\"http://www.opengis.net/ogc\"><And><PropertyIsLike wildCard=\"*\" singleChar=\".\" escapeChar=\"!\"><PropertyName>name</PropertyName><Literal>Mississippi*</Literal></PropertyIsLike><PropertyIsEqualTo><PropertyName>waterway</PropertyName><Literal>riverbank</Literal></PropertyIsEqualTo></And></Filter></Query></GetFeature>"
; function request(){ $.ajax({ type: 'POST', url: "http://demo.boundlessgeo.com/geoserver/wfs", data: string1, success: function (data) { console.log(data); }, error:function(data){ console.log(data); }, contentType:"text/plain;charset=UTF-8", dataType: "json" }) }
</script> </body> </html>

AJAX使用介紹