[OpenLayers-Users] OpenLayers.Request problem; where is the data?

Tim Schaub tschaub at opengeo.org
Mon Nov 3 15:02:46 EST 2008


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

Lehtonen, Mika wrote:
> 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 -
> 
> 
> Arnd Wippermann kirjoitti:
>> 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-bounces at openlayers.org [mailto:users-bounces at 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 -
>>
>> _______________________________________________
>> Users mailing list
>> Users at openlayers.org
>> http://openlayers.org/mailman/listinfo/users
>>
>>   
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users


-- 
Tim Schaub
OpenGeo - http://opengeo.org
Expert service straight from the developers.



More information about the Users mailing list