Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This may be simple question but I can't get started. This tutorial from pen state university has xml request

<wfs:GetFeature service="WFS"  version="1.0.0"
  outputFormat="GML2"  – we would like gml2 as the return format
  <wfs:Query typeName="topp:bc_roads">  we want to query 
                bc_roads features
      <ogc:FeatureId fid="bc_roads.1"/> only return features 
                                        with an ID of bc_roads.1

My question here is how do I send this request to geoserver using geoext or javascript?

share|improve this question
up vote 7 down vote accepted

You can do a post request in OpenLayers like this:

var postData = ""; //insert your data to post here

var request = new OpenLayers.Request.POST({
    url: "http://host/path",
    data: postData,
    headers: {
        "Content-Type": "text/xml;charset=utf-8"
    callback: function (response) {
        //read the response from GeoServer
        var gmlReader = new OpenLayers.Format.GML({ extractAttributes: true });
        var features =;
        // do what you want with the features returned...
    failure: function (response) {
        alert("Something went wrong in the request");

You can see more examples of how to request data in OpenLayers here:

Requesting Remote Data

share|improve this answer
great I will try this but I wanted to use geoext – kinkajou Feb 24 '12 at 6:36
Since GeoExt is an extension to combine ExtJS and OpenLayers, you might as well use OpenLayers to perform the request. You could use the XMLHttpRequest like BicycleDude suggest, but you could also use ExtJS to do the same. You have several API's at your hand - each capable of requesting :) – Chau Feb 24 '12 at 8:52

I'm going to make the following assumptions:

  • url = (which will be wrong)
  • your not using any library, i.e. no jQuery, no AJAX
  • you're interested in the built in XMLHttpRequest() object
  • you would like to handle asynchronous requests (instead of synchronous)
  • you can replace the error / success handler with something else
  • you wan't to see a minimal but complete working HTML

Here's the starter code in HTML / JavaScript:

<title>WMS Test</title>
<script language="JavaScript">
  function doit()
    var url = '';
    var method = 'POST';
    var postData =
      + '  service="WFS"\n'
      + '  version="1.0.0"\n'
      + '  outputFormat="GML2"\n'
      + '  xmlns:topp=""\n'
      + '  xmlns:wfs=""\n'
      + '  xmlns:ogc=""\n'
      + '  xmlns:xsi=""\n'
      + '  xsi:schemaLocation="\n'
      + '">\n'
      + '  <wfs:Query typeName="topp:bc_roads">\n'
      + '    <ogc:Filter>\n'
      + '      <ogc:FeatureId fid="bc_roads.1"/>\n'
      + '    </ogc:Filter>\n'
      + '    </wfs:Query>\n'
      + '</wfs:GetFeature>\n';
    var req = new XMLHttpRequest();"POST", url, true);
    req.setRequestHeader('User-Agent', 'XMLHTTP/1.0');
    req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    req.onreadystatechange = function () {
      if (req.readyState != 4) return;
      if (req.status != 200 && req.status != 304) {
        alert('HTTP error ' + req.status);
    if (req.readyState == 4) return;
<input type="button" value="doit" onclick="doit()"/>
share|improve this answer
+1 ...and probably using jQuery would not be a bad idea! – Ragi Yaser Burhum Feb 23 '12 at 17:20
+1 simple and great – kinkajou Feb 24 '12 at 6:36
Great suggestion, but the OP wanted to use GeoExt ;) – Chau Feb 24 '12 at 8:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.