Discussion:
OpenLayers.Request problem; where is the data?
(too old to reply)
Lehtonen, Mika
2008-11-03 09:01:22 UTC
Permalink
Hi,
I am trying to send a POST request from OL with the following snippet:

new OpenLayers.Request.issue({method: 'POST', url:'sld.php',
params:{abc:'def', cba:'fed'}, data:{ghi: 'jkl', ihg: 'lkj'},
success: function(){alert('Succeeded!');}, failure:
function(){alert('Did not succeed.');}, callback:
function(){alert('Calling back');}});

$_POST array in sld.php stays empty. In $_GET array I can find the
params: def and fed. How can I get touch with the data? Am I doing
something wrong here?

- mika -
Arnd Wippermann
2008-11-03 17:12:43 UTC
Permalink
Perhaps this solves the problem

headers: {
"Content-Type": "application/x-www-form-urlencoded"}

http://n2.nabble.com/OpenLayers.Request-POST-and-IE-6-7-issues-tt1384863.htm
l#a1395114


Arnd Wippermann


-----Ursprüngliche Nachricht-----
Von: users-***@openlayers.org [mailto:users-***@openlayers.org] Im
Auftrag von Lehtonen, Mika
Gesendet: Montag, 3. November 2008 10:01
An: OpenLayers
Betreff: [OpenLayers-Users] OpenLayers.Request problem; where is the data?

Hi,
I am trying to send a POST request from OL with the following snippet:

new OpenLayers.Request.issue({method: 'POST', url:'sld.php',
params:{abc:'def', cba:'fed'}, data:{ghi: 'jkl', ihg: 'lkj'},
success: function(){alert('Succeeded!');}, failure:
function(){alert('Did not succeed.');}, callback:
function(){alert('Calling back');}});

$_POST array in sld.php stays empty. In $_GET array I can find the
params: def and fed. How can I get touch with the data? Am I doing something
wrong here?

- mika -
Eric Lemoine
2008-11-03 17:17:09 UTC
Permalink
I was pointing Mika to the same thread. You beat on this one Arnd :-)
Thanks a lot for answering anyway. Cheers. Eric
Post by Arnd Wippermann
Perhaps this solves the problem
headers: {
"Content-Type": "application/x-www-form-urlencoded"}
http://n2.nabble.com/OpenLayers.Request-POST-and-IE-6-7-issues-tt1384863.htm
l#a1395114
Arnd Wippermann
-----Ursprüngliche Nachricht-----
Auftrag von Lehtonen, Mika
Gesendet: Montag, 3. November 2008 10:01
An: OpenLayers
Betreff: [OpenLayers-Users] OpenLayers.Request problem; where is the data?
Hi,
new OpenLayers.Request.issue({method: 'POST', url:'sld.php',
params:{abc:'def', cba:'fed'}, data:{ghi: 'jkl', ihg: 'lkj'},
function(){alert('Calling back');}});
$_POST array in sld.php stays empty. In $_GET array I can find the
params: def and fed. How can I get touch with the data? Am I doing something
wrong here?
- mika -
_______________________________________________
Users mailing list
http://openlayers.org/mailman/listinfo/users
_______________________________________________
Users mailing list
http://openlayers.org/ma
Lehtonen, Mika
2008-11-03 18:18:08 UTC
Permalink
Actually I already tested that. Also setting the Content-length and the
Connection Close. I haven't been testing this with other browsers than
FireFox. It seems that the POST method isn't responding in any way.
Parameters attached to the request however seem to be working just fine.

There was another issue, which might be the same you pointed to me, but
the symtons are closer to mine:

http://n2.nabble.com/OpenLayers.Request.POST-GET-errors-td1304742.html

- mika -
Post by Arnd Wippermann
Perhaps this solves the problem
headers: {
"Content-Type": "application/x-www-form-urlencoded"}
http://n2.nabble.com/OpenLayers.Request-POST-and-IE-6-7-issues-tt1384863.htm
l#a1395114
Arnd Wippermann
-----Ursprüngliche Nachricht-----
Auftrag von Lehtonen, Mika
Gesendet: Montag, 3. November 2008 10:01
An: OpenLayers
Betreff: [OpenLayers-Users] OpenLayers.Request problem; where is the data?
Hi,
new OpenLayers.Request.issue({method: 'POST', url:'sld.php',
params:{abc:'def', cba:'fed'}, data:{ghi: 'jkl', ihg: 'lkj'},
function(){alert('Calling back');}});
$_POST array in sld.php stays empty. In $_GET array I can find the
params: def and fed. How can I get touch with the data? Am I doing something
wrong here?
- mika -
_______________________________________________
Users mailing list
http://openlayers.org/mailman/listinfo/users
Tim Schaub
2008-11-03 20:02:46 UTC
Permalink
Hey-

Can you write (preferably not all on one line) what you are doing again
to make the request? If you are setting the content type, include that.
Also, note that you can use the POST function and that you don't need
the new keyword. In addition, note that params are about GET and data
is about POST.

I just set up PHP here and confirmed that the following works:

var req = OpenLayers.Request.POST({
url: "my.php",
data: OpenLayers.Util.getParameterString({foo: "bar"}),
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
})


The content of my.php:

<?php var_dump($_POST); ?>


What I see in the response:

array(1) {
["foo"]=>
string(3) "bar"
}


The same answer is given here:
http://openlayers.org/pipermail/users/2008-October/008483.html

I've put this example up on the Request wiki page:
http://trac.openlayers.org/wiki/Request#Ex.7:IssueaPOSTrequestwithform-encodeddata.

And, this is now a FAQ:
http://faq.openlayers.org/ajax/how-do-i-post-form-encoded-data/

Good luck,
Tim
Post by Lehtonen, Mika
Actually I already tested that. Also setting the Content-length and the
Connection Close. I haven't been testing this with other browsers than
FireFox. It seems that the POST method isn't responding in any way.
Parameters attached to the request however seem to be working just fine.
There was another issue, which might be the same you pointed to me, but
http://n2.nabble.com/OpenLayers.Request.POST-GET-errors-td1304742.html
- mika -
Post by Arnd Wippermann
Perhaps this solves the problem
headers: {
"Content-Type": "application/x-www-form-urlencoded"}
http://n2.nabble.com/OpenLayers.Request-POST-and-IE-6-7-issues-tt1384863.htm
l#a1395114
Arnd Wippermann
-----Ursprüngliche Nachricht-----
Auftrag von Lehtonen, Mika
Gesendet: Montag, 3. November 2008 10:01
An: OpenLayers
Betreff: [OpenLayers-Users] OpenLayers.Request problem; where is the data?
Hi,
new OpenLayers.Request.issue({method: 'POST', url:'sld.php',
params:{abc:'def', cba:'fed'}, data:{ghi: 'jkl', ihg: 'lkj'},
function(){alert('Calling back');}});
$_POST array in sld.php stays empty. In $_GET array I can find the
params: def and fed. How can I get touch with the data? Am I doing something
wrong here?
- mika -
_______________________________________________
Users mailing list
http://openlayers.org/mailman/listinfo/users
_______________________________________________
Users mailing list
http://openlayers.org/mailman/listinfo/users
--
Tim Schaub
OpenGeo - http://opengeo.org
Expert service straight from the developers.
Lehtonen, Mika
2008-11-03 20:36:20 UTC
Permalink
Hi Tim,

tested that. I get this: array(0) { }

I am trying to create a SLD on server side for Geoserver, based on what
has been selected on client side. So I have quite a huge number (couple
of thousands) of polygon regions of which an end user can choose from
(with a "tool"). Chosen polygons should be presented with different
style. So I decided to do that using wms. Unfortunately, if I create my
SLD on client side and send it server by using GET, the request is way
too long.

Basically, an array of certain selected polygon attributes POSTED to
server, would be enough.

- mika -
Post by Tim Schaub
Hey-
Can you write (preferably not all on one line) what you are doing again
to make the request? If you are setting the content type, include that.
Also, note that you can use the POST function and that you don't need
the new keyword. In addition, note that params are about GET and data
is about POST.
var req = OpenLayers.Request.POST({
url: "my.php",
data: OpenLayers.Util.getParameterString({foo: "bar"}),
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
})
<?php var_dump($_POST); ?>
array(1) {
["foo"]=>
string(3) "bar"
}
http://openlayers.org/pipermail/users/2008-October/008483.html
http://trac.openlayers.org/wiki/Request#Ex.7:IssueaPOSTrequestwithform-encodeddata.
http://faq.openlayers.org/ajax/how-do-i-post-form-encoded-data/
Good luck,
Tim
Post by Lehtonen, Mika
Actually I already tested that. Also setting the Content-length and the
Connection Close. I haven't been testing this with other browsers than
FireFox. It seems that the POST method isn't responding in any way.
Parameters attached to the request however seem to be working just fine.
There was another issue, which might be the same you pointed to me, but
http://n2.nabble.com/OpenLayers.Request.POST-GET-errors-td1304742.html
- mika -
Post by Arnd Wippermann
Perhaps this solves the problem
headers: {
"Content-Type": "application/x-www-form-urlencoded"}
http://n2.nabble.com/OpenLayers.Request-POST-and-IE-6-7-issues-tt1384863.htm
l#a1395114
Arnd Wippermann
-----Ursprüngliche Nachricht-----
Auftrag von Lehtonen, Mika
Gesendet: Montag, 3. November 2008 10:01
An: OpenLayers
Betreff: [OpenLayers-Users] OpenLayers.Request problem; where is the data?
Hi,
new OpenLayers.Request.issue({method: 'POST', url:'sld.php',
params:{abc:'def', cba:'fed'}, data:{ghi: 'jkl', ihg: 'lkj'},
function(){alert('Calling back');}});
$_POST array in sld.php stays empty. In $_GET array I can find the
params: def and fed. How can I get touch with the data? Am I doing something
wrong here?
- mika -
_______________________________________________
Users mailing list
http://openlayers.org/mailman/listinfo/users
_______________________________________________
Users mailing list
http://openlayers.org/mailman/listinfo/users
Lehtonen, Mika
2008-11-03 20:42:35 UTC
Permalink
Hi again,
using $_REQUEST (with your snippet), I get this. What's that?

array(2) {
["__utma"]=>
string(54) "81555458.1737773788.1225666548.1225666548.1225666548.1"
["__utmz"]=>
string(69) "81555458.1225666548.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none)"
}

- mika -
Post by Lehtonen, Mika
Hi Tim,
tested that. I get this: array(0) { }
I am trying to create a SLD on server side for Geoserver, based on what
has been selected on client side. So I have quite a huge number (couple
of thousands) of polygon regions of which an end user can choose from
(with a "tool"). Chosen polygons should be presented with different
style. So I decided to do that using wms. Unfortunately, if I create my
SLD on client side and send it server by using GET, the request is way
too long.
Basically, an array of certain selected polygon attributes POSTED to
server, would be enough.
- mika -
Post by Tim Schaub
Hey-
Can you write (preferably not all on one line) what you are doing again
to make the request? If you are setting the content type, include that.
Also, note that you can use the POST function and that you don't need
the new keyword. In addition, note that params are about GET and data
is about POST.
var req = OpenLayers.Request.POST({
url: "my.php",
data: OpenLayers.Util.getParameterString({foo: "bar"}),
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
})
<?php var_dump($_POST); ?>
array(1) {
["foo"]=>
string(3) "bar"
}
http://openlayers.org/pipermail/users/2008-October/008483.html
http://trac.openlayers.org/wiki/Request#Ex.7:IssueaPOSTrequestwithform-encodeddata.
http://faq.openlayers.org/ajax/how-do-i-post-form-encoded-data/
Good luck,
Tim
Post by Lehtonen, Mika
Actually I already tested that. Also setting the Content-length and the
Connection Close. I haven't been testing this with other browsers than
FireFox. It seems that the POST method isn't responding in any way.
Parameters attached to the request however seem to be working just fine.
There was another issue, which might be the same you pointed to me, but
http://n2.nabble.com/OpenLayers.Request.POST-GET-errors-td1304742.html
- mika -
Post by Arnd Wippermann
Perhaps this solves the problem
headers: {
"Content-Type": "application/x-www-form-urlencoded"}
http://n2.nabble.com/OpenLayers.Request-POST-and-IE-6-7-issues-tt1384863.htm
l#a1395114
Arnd Wippermann
-----Ursprüngliche Nachricht-----
Auftrag von Lehtonen, Mika
Gesendet: Montag, 3. November 2008 10:01
An: OpenLayers
Betreff: [OpenLayers-Users] OpenLayers.Request problem; where is the data?
Hi,
new OpenLayers.Request.issue({method: 'POST', url:'sld.php',
params:{abc:'def', cba:'fed'}, data:{ghi: 'jkl', ihg: 'lkj'},
function(){alert('Calling back');}});
$_POST array in sld.php stays empty. In $_GET array I can find the
params: def and fed. How can I get touch with the data? Am I doing something
wrong here?
- mika -
_______________________________________________
Users mailing list
http://openlayers.org/mailman/listinfo/users
_______________________________________________
Users mailing list
http://openlayers.org/mailman/listinfo/users
_______________________________________________
Users mailing list
http://openlayers.org/mailman/listinfo/users
Tim Schaub
2008-11-03 21:29:58 UTC
Permalink
Hey-
Post by Lehtonen, Mika
Hi again,
using $_REQUEST (with your snippet), I get this. What's that?
array(2) {
["__utma"]=>
string(54) "81555458.1737773788.1225666548.1225666548.1225666548.1"
["__utmz"]=>
string(69)
"81555458.1225666548.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none)"
}
Those are cookie values.

We (or I at least) can only help you out if you post code (preferably
legible).

Thanks,
Tim
Post by Lehtonen, Mika
- mika -
Post by Lehtonen, Mika
Hi Tim,
tested that. I get this: array(0) { }
I am trying to create a SLD on server side for Geoserver, based on
what has been selected on client side. So I have quite a huge number
(couple of thousands) of polygon regions of which an end user can
choose from (with a "tool"). Chosen polygons should be presented with
different style. So I decided to do that using wms. Unfortunately, if
I create my SLD on client side and send it server by using GET, the
request is way too long.
Basically, an array of certain selected polygon attributes POSTED to
server, would be enough.
- mika -
Post by Tim Schaub
Hey-
Can you write (preferably not all on one line) what you are doing
again to make the request? If you are setting the content type,
include that. Also, note that you can use the POST function and
that you don't need the new keyword. In addition, note that params
are about GET and data is about POST.
var req = OpenLayers.Request.POST({
url: "my.php",
data: OpenLayers.Util.getParameterString({foo: "bar"}),
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
})
<?php var_dump($_POST); ?>
array(1) {
["foo"]=>
string(3) "bar"
}
http://openlayers.org/pipermail/users/2008-October/008483.html
http://trac.openlayers.org/wiki/Request#Ex.7:IssueaPOSTrequestwithform-encodeddata.
http://faq.openlayers.org/ajax/how-do-i-post-form-encoded-data/
Good luck,
Tim
Post by Lehtonen, Mika
Actually I already tested that. Also setting the Content-length and
the Connection Close. I haven't been testing this with other
browsers than FireFox. It seems that the POST method isn't
responding in any way. Parameters attached to the request however
seem to be working just fine.
There was another issue, which might be the same you pointed to me,
http://n2.nabble.com/OpenLayers.Request.POST-GET-errors-td1304742.html
- mika -
Post by Arnd Wippermann
Perhaps this solves the problem
headers: {
"Content-Type": "application/x-www-form-urlencoded"}
http://n2.nabble.com/OpenLayers.Request-POST-and-IE-6-7-issues-tt1384863.htm
l#a1395114
Arnd Wippermann
-----Ursprüngliche Nachricht-----
Auftrag von Lehtonen, Mika
Gesendet: Montag, 3. November 2008 10:01
An: OpenLayers
Betreff: [OpenLayers-Users] OpenLayers.Request problem; where is the data?
Hi,
new OpenLayers.Request.issue({method: 'POST', url:'sld.php',
params:{abc:'def', cba:'fed'}, data:{ghi: 'jkl', ihg: 'lkj'},
function(){alert('Calling back');}});
$_POST array in sld.php stays empty. In $_GET array I can find the
params: def and fed. How can I get touch with the data? Am I doing something
wrong here?
- mika -
_______________________________________________
Users mailing list
http://openlayers.org/mailman/listinfo/users
_______________________________________________
Users mailing list
http://openlayers.org/mailman/listinfo/users
_______________________________________________
Users mailing list
http://openlayers.org/mailman/listinfo/users
--
Tim Schaub
OpenGeo - http://opengeo.org
Expert service straight from the developers.
Tim Schaub
2008-11-03 21:41:23 UTC
Permalink
Hey-
Post by Tim Schaub
Hey-
Post by Lehtonen, Mika
Hi again,
using $_REQUEST (with your snippet), I get this. What's that?
array(2) {
["__utma"]=>
string(54) "81555458.1737773788.1225666548.1225666548.1225666548.1"
["__utmz"]=>
string(69)
"81555458.1225666548.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none)"
}
Those are cookie values.
We (or I at least) can only help you out if you post code (preferably
legible).
Thanks,
Tim
Post by Lehtonen, Mika
- mika -
Post by Lehtonen, Mika
Hi Tim,
tested that. I get this: array(0) { }
If you really are doing exactly what I put below (creating a simple
my.pyp thingy and POSTing using that exact syntax), then you could be
having a character encoding issue.

I don't know enough about PHP to know what they expect or handle - or
how your installation is configured or what character set your browser
may be using, but you might have to specify your charset in the
Content-Type header:

var req = OpenLayers.Request.POST({
url: "my.php",
data: OpenLayers.Util.getParameterString({foo: "bar"}),
headers: {
"Content-Type":
"application/x-www-form-urlencoded; charset=utf-8"
}
});

If you are still having trouble, you'll probably want to spend some time
with curl, RestTest (FF2 only), LiveHTTPHeaders, and/or other tools to
examine exactly what is going on.

Also, in your first post (to this list), you were using an object as the
data value. This needs to be a form-encoded string. Note that I am
using the OpenLayers.Util.getParameterString function above to get a
form-encoded string from an object.

Tim
Post by Tim Schaub
Post by Lehtonen, Mika
Post by Lehtonen, Mika
I am trying to create a SLD on server side for Geoserver, based on
what has been selected on client side. So I have quite a huge number
(couple of thousands) of polygon regions of which an end user can
choose from (with a "tool"). Chosen polygons should be presented with
different style. So I decided to do that using wms. Unfortunately, if
I create my SLD on client side and send it server by using GET, the
request is way too long.
Basically, an array of certain selected polygon attributes POSTED to
server, would be enough.
- mika -
Post by Tim Schaub
Hey-
Can you write (preferably not all on one line) what you are doing
again to make the request? If you are setting the content type,
include that. Also, note that you can use the POST function and
that you don't need the new keyword. In addition, note that params
are about GET and data is about POST.
var req = OpenLayers.Request.POST({
url: "my.php",
data: OpenLayers.Util.getParameterString({foo: "bar"}),
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
})
<?php var_dump($_POST); ?>
array(1) {
["foo"]=>
string(3) "bar"
}
http://openlayers.org/pipermail/users/2008-October/008483.html
http://trac.openlayers.org/wiki/Request#Ex.7:IssueaPOSTrequestwithform-encodeddata.
http://faq.openlayers.org/ajax/how-do-i-post-form-encoded-data/
Good luck,
Tim
Post by Lehtonen, Mika
Actually I already tested that. Also setting the Content-length and
the Connection Close. I haven't been testing this with other
browsers than FireFox. It seems that the POST method isn't
responding in any way. Parameters attached to the request however
seem to be working just fine.
There was another issue, which might be the same you pointed to me,
http://n2.nabble.com/OpenLayers.Request.POST-GET-errors-td1304742.html
- mika -
Post by Arnd Wippermann
Perhaps this solves the problem
headers: {
"Content-Type": "application/x-www-form-urlencoded"}
http://n2.nabble.com/OpenLayers.Request-POST-and-IE-6-7-issues-tt1384863.htm
l#a1395114
Arnd Wippermann
-----Ursprüngliche Nachricht-----
Auftrag von Lehtonen, Mika
Gesendet: Montag, 3. November 2008 10:01
An: OpenLayers
Betreff: [OpenLayers-Users] OpenLayers.Request problem; where is the data?
Hi,
new OpenLayers.Request.issue({method: 'POST', url:'sld.php',
params:{abc:'def', cba:'fed'}, data:{ghi: 'jkl', ihg: 'lkj'},
function(){alert('Calling back');}});
$_POST array in sld.php stays empty. In $_GET array I can find the
params: def and fed. How can I get touch with the data? Am I doing something
wrong here?
- mika -
_______________________________________________
Users mailing list
http://openlayers.org/mailman/listinfo/users
_______________________________________________
Users mailing list
http://openlayers.org/mailman/listinfo/users
_______________________________________________
Users mailing list
http://openlayers.org/mailman/listinfo/users
--
Tim Schaub
OpenGeo - http://opengeo.org
Expert service straight from the developers.
Lehtonen, Mika
2008-11-03 21:55:32 UTC
Permalink
Ok,

I'll get back to this when I have time. Thanks a lot.
BTW: This is what OL API doc says about 'data': {Object} Any data to
send with the request.
http://dev.openlayers.org/releases/OpenLayers-2.7/doc/apidocs/files/OpenLayers/Request-js.html
Maybe I took that too literally. ;-)

- mika -
Post by Tim Schaub
Hey-
Post by Tim Schaub
Hey-
Post by Lehtonen, Mika
Hi again,
using $_REQUEST (with your snippet), I get this. What's that?
array(2) {
["__utma"]=>
string(54) "81555458.1737773788.1225666548.1225666548.1225666548.1"
["__utmz"]=>
string(69)
"81555458.1225666548.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none)"
}
Those are cookie values.
We (or I at least) can only help you out if you post code (preferably
legible).
Thanks,
Tim
Post by Lehtonen, Mika
- mika -
Post by Lehtonen, Mika
Hi Tim,
tested that. I get this: array(0) { }
If you really are doing exactly what I put below (creating a simple
my.pyp thingy and POSTing using that exact syntax), then you could be
having a character encoding issue.
I don't know enough about PHP to know what they expect or handle - or
how your installation is configured or what character set your browser
may be using, but you might have to specify your charset in the
var req = OpenLayers.Request.POST({
url: "my.php",
data: OpenLayers.Util.getParameterString({foo: "bar"}),
headers: {
"application/x-www-form-urlencoded; charset=utf-8"
}
});
If you are still having trouble, you'll probably want to spend some time
with curl, RestTest (FF2 only), LiveHTTPHeaders, and/or other tools to
examine exactly what is going on.
Also, in your first post (to this list), you were using an object as the
data value. This needs to be a form-encoded string. Note that I am
using the OpenLayers.Util.getParameterString function above to get a
form-encoded string from an object.
Tim
Post by Tim Schaub
Post by Lehtonen, Mika
Post by Lehtonen, Mika
I am trying to create a SLD on server side for Geoserver, based on
what has been selected on client side. So I have quite a huge number
(couple of thousands) of polygon regions of which an end user can
choose from (with a "tool"). Chosen polygons should be presented with
different style. So I decided to do that using wms. Unfortunately, if
I create my SLD on client side and send it server by using GET, the
request is way too long.
Basically, an array of certain selected polygon attributes POSTED to
server, would be enough.
- mika -
Post by Tim Schaub
Hey-
Can you write (preferably not all on one line) what you are doing
again to make the request? If you are setting the content type,
include that. Also, note that you can use the POST function and
that you don't need the new keyword. In addition, note that params
are about GET and data is about POST.
var req = OpenLayers.Request.POST({
url: "my.php",
data: OpenLayers.Util.getParameterString({foo: "bar"}),
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
})
<?php var_dump($_POST); ?>
array(1) {
["foo"]=>
string(3) "bar"
}
http://openlayers.org/pipermail/users/2008-October/008483.html
http://trac.openlayers.org/wiki/Request#Ex.7:IssueaPOSTrequestwithform-encodeddata.
http://faq.openlayers.org/ajax/how-do-i-post-form-encoded-data/
Good luck,
Tim
Post by Lehtonen, Mika
Actually I already tested that. Also setting the Content-length and
the Connection Close. I haven't been testing this with other
browsers than FireFox. It seems that the POST method isn't
responding in any way. Parameters attached to the request however
seem to be working just fine.
There was another issue, which might be the same you pointed to me,
http://n2.nabble.com/OpenLayers.Request.POST-GET-errors-td1304742.html
- mika -
Post by Arnd Wippermann
Perhaps this solves the problem
headers: {
"Content-Type": "application/x-www-form-urlencoded"}
http://n2.nabble.com/OpenLayers.Request-POST-and-IE-6-7-issues-tt1384863.htm
l#a1395114
Arnd Wippermann
-----Ursprüngliche Nachricht-----
Auftrag von Lehtonen, Mika
Gesendet: Montag, 3. November 2008 10:01
An: OpenLayers
Betreff: [OpenLayers-Users] OpenLayers.Request problem; where is the data?
Hi,
new OpenLayers.Request.issue({method: 'POST', url:'sld.php',
params:{abc:'def', cba:'fed'}, data:{ghi: 'jkl', ihg: 'lkj'},
function(){alert('Calling back');}});
$_POST array in sld.php stays empty. In $_GET array I can find the
params: def and fed. How can I get touch with the data? Am I doing something
wrong here?
- mika -
_______________________________________________
Users mailing list
http://openlayers.org/mailman/listinfo/users
_______________________________________________
Users mailing list
http://openlayers.org/mailman/listinfo/users
_______________________________________________
Users mailing list
http://openlayers.org/mailman/listinfo/users
Tim Schaub
2008-11-04 05:04:54 UTC
Permalink
Hey-
Post by Lehtonen, Mika
Ok,
I'll get back to this when I have time. Thanks a lot.
BTW: This is what OL API doc says about 'data': {Object} Any data to
send with the request.
http://dev.openlayers.org/releases/OpenLayers-2.7/doc/apidocs/files/OpenLayers/Request-js.html
Maybe I took that too literally. ;-)
Yes, that should be {String | Document}. I'll change it and add a bit
more detail. Thanks for pointing that out.

Still, the important part to understand is the Content-Type header.
Your data (string or document) could be one of any number of types of
data. The server won't know what to do with the data unless you tell it
the content type.

The data here is the argument to the send method of XMLHttpRequest. You
can read more about that here:

http://www.w3.org/TR/XMLHttpRequest/

or, for the Mozilla implementation:

https://developer.mozilla.org/En/XMLHttpRequest

Tim
Post by Lehtonen, Mika
- mika -
Post by Tim Schaub
Hey-
Post by Tim Schaub
Hey-
Post by Lehtonen, Mika
Hi again,
using $_REQUEST (with your snippet), I get this. What's that?
array(2) {
["__utma"]=>
string(54) "81555458.1737773788.1225666548.1225666548.1225666548.1"
["__utmz"]=>
string(69)
"81555458.1225666548.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none)"
}
Those are cookie values.
We (or I at least) can only help you out if you post code (preferably
legible).
Thanks,
Tim
Post by Lehtonen, Mika
- mika -
Post by Lehtonen, Mika
Hi Tim,
tested that. I get this: array(0) { }
If you really are doing exactly what I put below (creating a simple
my.pyp thingy and POSTing using that exact syntax), then you could be
having a character encoding issue.
I don't know enough about PHP to know what they expect or handle - or
how your installation is configured or what character set your browser
may be using, but you might have to specify your charset in the
var req = OpenLayers.Request.POST({
url: "my.php",
data: OpenLayers.Util.getParameterString({foo: "bar"}),
headers: {
"application/x-www-form-urlencoded; charset=utf-8"
}
});
If you are still having trouble, you'll probably want to spend some
time with curl, RestTest (FF2 only), LiveHTTPHeaders, and/or other
tools to examine exactly what is going on.
Also, in your first post (to this list), you were using an object as
the data value. This needs to be a form-encoded string. Note that I
am using the OpenLayers.Util.getParameterString function above to get
a form-encoded string from an object.
Tim
Post by Tim Schaub
Post by Lehtonen, Mika
Post by Lehtonen, Mika
I am trying to create a SLD on server side for Geoserver, based on
what has been selected on client side. So I have quite a huge
number (couple of thousands) of polygon regions of which an end
user can choose from (with a "tool"). Chosen polygons should be
presented with different style. So I decided to do that using wms.
Unfortunately, if I create my SLD on client side and send it server
by using GET, the request is way too long.
Basically, an array of certain selected polygon attributes POSTED
to server, would be enough.
- mika -
Post by Tim Schaub
Hey-
Can you write (preferably not all on one line) what you are doing
again to make the request? If you are setting the content type,
include that. Also, note that you can use the POST function and
that you don't need the new keyword. In addition, note that
params are about GET and data is about POST.
var req = OpenLayers.Request.POST({
url: "my.php",
data: OpenLayers.Util.getParameterString({foo: "bar"}),
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
})
<?php var_dump($_POST); ?>
array(1) {
["foo"]=>
string(3) "bar"
}
http://openlayers.org/pipermail/users/2008-October/008483.html
http://trac.openlayers.org/wiki/Request#Ex.7:IssueaPOSTrequestwithform-encodeddata.
http://faq.openlayers.org/ajax/how-do-i-post-form-encoded-data/
Good luck,
Tim
Post by Lehtonen, Mika
Actually I already tested that. Also setting the Content-length
and the Connection Close. I haven't been testing this with other
browsers than FireFox. It seems that the POST method isn't
responding in any way. Parameters attached to the request however
seem to be working just fine.
There was another issue, which might be the same you pointed to
http://n2.nabble.com/OpenLayers.Request.POST-GET-errors-td1304742.html
- mika -
Post by Arnd Wippermann
Perhaps this solves the problem
headers: {
"Content-Type": "application/x-www-form-urlencoded"}
http://n2.nabble.com/OpenLayers.Request-POST-and-IE-6-7-issues-tt1384863.htm
l#a1395114
Arnd Wippermann
-----Ursprüngliche Nachricht-----
Auftrag von Lehtonen, Mika
Gesendet: Montag, 3. November 2008 10:01
An: OpenLayers
Betreff: [OpenLayers-Users] OpenLayers.Request problem; where is the data?
Hi,
new OpenLayers.Request.issue({method: 'POST', url:'sld.php',
params:{abc:'def', cba:'fed'}, data:{ghi: 'jkl', ihg: 'lkj'},
function(){alert('Calling back');}});
$_POST array in sld.php stays empty. In $_GET array I can find the
params: def and fed. How can I get touch with the data? Am I doing something
wrong here?
- mika -
_______________________________________________
Users mailing list
http://openlayers.org/mailman/listinfo/users
_______________________________________________
Users mailing list
http://openlayers.org/mailman/listinfo/users
_______________________________________________
Users mailing list
http://openlayers.org/mailman/listinfo/users
--
Tim Schaub
OpenGeo - http://opengeo.org
Expert service straight from the developers.
Lehtonen, Mika
2008-11-04 17:48:04 UTC
Permalink
Darn Tim,
I feel stupid. You were right about the Content-type and the
Form-encoded string as a data type. But the most stupid thing I did was
to obey an instruction I read from some where in the internet. It said
that request responses can be observed by clicking the right mouse
button on top of the request in Firebug and then selecting 'Open in New
Tab'. In case of POST it definetely isn't showing any response from $_POST.
So this one works like yours:
var req = OpenLayers.Request.issue({
method: 'POST', url:'sld.php', params:{abc:'def', cba:'fed'},
data:OpenLayers.Util.getParameterString({foo: "bar"}),
headers:{"Content-Type": "application/x-www-form-urlencoded" },
success: function(){alert('Succeeded!');}, failure:
function(){alert('Did not succeed.');}, callback:
function(){alert('Calling back');} });

This never did (the original):
new OpenLayers.Request.issue({
method: 'POST', url:'sld.php', params:{abc:'def', cba:'fed'}, data:{ghi:
'jkl', ihg: 'lkj'},
success: function(){alert('Succeeded!');}, failure:
function(){alert('Did not succeed.');}, callback:
function(){alert('Calling back');}});

Thanks very much for your help,
- mika -

P.S. Any idea what's the best way to post an array?
Post by Tim Schaub
Hey-
Post by Lehtonen, Mika
Ok,
I'll get back to this when I have time. Thanks a lot.
BTW: This is what OL API doc says about 'data': {Object} Any data to
send with the request.
http://dev.openlayers.org/releases/OpenLayers-2.7/doc/apidocs/files/OpenLayers/Request-js.html
Maybe I took that too literally. ;-)
Yes, that should be {String | Document}. I'll change it and add a bit
more detail. Thanks for pointing that out.
Still, the important part to understand is the Content-Type header.
Your data (string or document) could be one of any number of types of
data. The server won't know what to do with the data unless you tell it
the content type.
The data here is the argument to the send method of XMLHttpRequest. You
http://www.w3.org/TR/XMLHttpRequest/
https://developer.mozilla.org/En/XMLHttpRequest
Tim
Post by Lehtonen, Mika
- mika -
Post by Tim Schaub
Hey-
Post by Tim Schaub
Hey-
Post by Lehtonen, Mika
Hi again,
using $_REQUEST (with your snippet), I get this. What's that?
array(2) {
["__utma"]=>
string(54) "81555458.1737773788.1225666548.1225666548.1225666548.1"
["__utmz"]=>
string(69)
"81555458.1225666548.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none)"
}
Those are cookie values.
We (or I at least) can only help you out if you post code (preferably
legible).
Thanks,
Tim
Post by Lehtonen, Mika
- mika -
Post by Lehtonen, Mika
Hi Tim,
tested that. I get this: array(0) { }
If you really are doing exactly what I put below (creating a simple
my.pyp thingy and POSTing using that exact syntax), then you could be
having a character encoding issue.
I don't know enough about PHP to know what they expect or handle - or
how your installation is configured or what character set your browser
may be using, but you might have to specify your charset in the
var req = OpenLayers.Request.POST({
url: "my.php",
data: OpenLayers.Util.getParameterString({foo: "bar"}),
headers: {
"application/x-www-form-urlencoded; charset=utf-8"
}
});
If you are still having trouble, you'll probably want to spend some
time with curl, RestTest (FF2 only), LiveHTTPHeaders, and/or other
tools to examine exactly what is going on.
Also, in your first post (to this list), you were using an object as
the data value. This needs to be a form-encoded string. Note that I
am using the OpenLayers.Util.getParameterString function above to get
a form-encoded string from an object.
Tim
Post by Tim Schaub
Post by Lehtonen, Mika
Post by Lehtonen, Mika
I am trying to create a SLD on server side for Geoserver, based on
what has been selected on client side. So I have quite a huge
number (couple of thousands) of polygon regions of which an end
user can choose from (with a "tool"). Chosen polygons should be
presented with different style. So I decided to do that using wms.
Unfortunately, if I create my SLD on client side and send it server
by using GET, the request is way too long.
Basically, an array of certain selected polygon attributes POSTED
to server, would be enough.
- mika -
Post by Tim Schaub
Hey-
Can you write (preferably not all on one line) what you are doing
again to make the request? If you are setting the content type,
include that. Also, note that you can use the POST function and
that you don't need the new keyword. In addition, note that
params are about GET and data is about POST.
var req = OpenLayers.Request.POST({
url: "my.php",
data: OpenLayers.Util.getParameterString({foo: "bar"}),
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
})
<?php var_dump($_POST); ?>
array(1) {
["foo"]=>
string(3) "bar"
}
http://openlayers.org/pipermail/users/2008-October/008483.html
http://trac.openlayers.org/wiki/Request#Ex.7:IssueaPOSTrequestwithform-encodeddata.
http://faq.openlayers.org/ajax/how-do-i-post-form-encoded-data/
Good luck,
Tim
Post by Lehtonen, Mika
Actually I already tested that. Also setting the Content-length
and the Connection Close. I haven't been testing this with other
browsers than FireFox. It seems that the POST method isn't
responding in any way. Parameters attached to the request however
seem to be working just fine.
There was another issue, which might be the same you pointed to
http://n2.nabble.com/OpenLayers.Request.POST-GET-errors-td1304742.html
- mika -
Post by Arnd Wippermann
Perhaps this solves the problem
headers: {
"Content-Type": "application/x-www-form-urlencoded"}
http://n2.nabble.com/OpenLayers.Request-POST-and-IE-6-7-issues-tt1384863.htm
l#a1395114
Arnd Wippermann
-----Ursprüngliche Nachricht-----
Auftrag von Lehtonen, Mika
Gesendet: Montag, 3. November 2008 10:01
An: OpenLayers
Betreff: [OpenLayers-Users] OpenLayers.Request problem; where is the data?
Hi,
new OpenLayers.Request.issue({method: 'POST', url:'sld.php',
params:{abc:'def', cba:'fed'}, data:{ghi: 'jkl', ihg: 'lkj'},
function(){alert('Calling back');}});
$_POST array in sld.php stays empty. In $_GET array I can find the
params: def and fed. How can I get touch with the data? Am I
doing something
wrong here?
- mika -
_______________________________________________
Users mailing list
http://openlayers.org/mailman/listinfo/users
_______________________________________________
Users mailing list
http://openlayers.org/mailman/listinfo/users
_______________________________________________
Users mailing list
http://openlayers.org/mailman/listinfo/users
Continue reading on narkive:
Loading...