[OpenLayers-Users] Example Needed Demonstrating
OpenLayers.Request
Bill Thoen
bthoen at gisnet.com
Fri Jan 9 16:16:00 EST 2009
Christopher Schmidt wrote:
> On Fri, Jan 09, 2009 at 01:24:27PM -0700, Bill Thoen wrote:
>
>> Does anyone have a simple example showing how to use OpenLayers.Request
>> to move data back and forth between an OL application and a
>> PostgreSQL/PostGIS database? I got this to work using zXml library
>> calls, but if I can do the same thing from within the OpenLayers
>> framework, then I wouldn't need to load that library. Unfortunately, I'm
>> still pretty new to AJAX, and the lack of detailed documentation on the
>> OpenLayers.Request class puts this out of my reach without some help.
>>
>
> More than:
>
> http://trac.openlayers.org/wiki/Request
>
> Isn't somethign I'd know how to write at this point anyway. Can you
> explain what that page doesn't tell you that you feel you need to know?
>
> Regards,
>
Thanks, I didn't see this. But even this is still too abstract for me
because I don't yet have a good grip on how AJAX is supposed to work and
what configuration settings I need to modify vs what's already set up as
defaults. Here's what I've got using the zXml library (this works, but
I'd rather not load the zXml library if I've got what I need in OpenLayers):
var oXHR = zXmlHttp.createRequest();
oXHR.open( "POST", "sql.php", true );
oXHR.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");
oXHR.setRequestHeader("Content-length", params.length);
oXHR.setRequestHeader("Connection", "close");
oXHR.onreadystatechange = function() {
if( oXHR.readyState == 4 ) {
xmlDoc = oXHR.responseXML;
// parse the results here
}
}
oXHR.send( params );
What I want to know is how to modify this to use the OpenLayers library
instead of the zXml one. Questions I have are: is it 'sql.php' that I
set the url to? Are those headers standard with the default
configuration or do I have to add them? The 'params' variable here holds
a complete SQL query that I pass to the database via a PHP script called
sql.php. Is that considered the 'data', or should it be specified under
a different config parameter? I imagine that the callback is the
onreadystatechange function which will probably have to be made into a
named function, right?
As you can probably tell, I don't really know enough yet about AJAX to
even know what I don't know, so I'm sort of like a blind dog in a meat
market, stabbing at anything that smells good. I don't even know if this
is what I want to do, but it seems like the right track to take for
accessing my PostgreSQL database from an OpenLayers application. I could
use a clue or two if anyone has some advice or some pointers to more
information about working with databases from OpenLayers.
More information about the Users
mailing list