我正在尝试使用ajax post向geoserver发送http post请求。我在chrome中遇到以下错误。
Uncaught SyntaxError: Unexpected identifier
当我使用数据时:--my query--
和
Uncaught SyntaxError: Unexpected token ILLEGAL
当我使用数据时:--my query--
。
我看到错误是由于结束标记引起的,例如:</ogc:PropertyName>
这是我的代码:
$.ajax({
type: "POST",
url: "http://localhost/geoserver",
data: '
<wfs:GetFeature
xmlns:wfs="http://www.opengis.net/wfs"
xmlns:ogc="http://www.opengis.net/ogc"
service="WFS" version="1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd"
maxFeatures= "13" >
<wfs:Query typeName="*:MyFeatures_df16" xmlns:feature="http://www.openplans.org/topp">
<ogc:Filter>
<ogc:And>
<ogc:Or>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>ID</ogc:PropertyName>
<ogc:Literal>98400005701</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Or>
</ogc:And>
</ogc:Filter>
</wfs:Query>
</wfs:GetFeature> ',
contentType: "text/xml",
dataType:"text",
crossDomain: true,
cache: false,
error: function() {alert('it doesnt work')},
success: function(result){ $("#div1").html(result);}
});
});
});
答案 0 :(得分:1)
您没有命名要在Ajax调用中发送的数据,而是发送没有密钥的字符串。在你的情况下,我要传递一个带有键或对象的字符串。
来源 - http://api.jquery.com/jquery.ajax/
尝试 -
data: { xml: encodeURIComponent('
<wfs:GetFeature
xmlns:wfs="http://www.opengis.net/wfs"
xmlns:ogc="http://www.opengis.net/ogc"
service="WFS" version="1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd"
maxFeatures= "13" >
<wfs:Query typeName="*:MyFeatures_df16" xmlns:feature="http://www.openplans.org/topp">
<ogc:Filter>
<ogc:And>
<ogc:Or>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>ID</ogc:PropertyName>
<ogc:Literal>98400005701</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Or>
</ogc:And>
</ogc:Filter>
</wfs:Query>
</wfs:GetFeature> ')}
答案 1 :(得分:0)
$.ajax({
type: "POST",
url: "http://localhost/geoserver",
data: 'http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd" maxFeatures= "13" > ID 98400005701',
contentType: "text/xml",
dataType:"text",
crossDomain: true,
cache: false,
error: function() {alert('it doesnt work');},
success: function(result){ $("#div1").html(result); }
});
如果你真的正确地格式化它,你会发现你错过了一些逗号和东西。我不知道你要对你的数据做什么,但那可能就是它出错了。