xpmstos wrote:
> I use a generic PHP server which uses the PECL ext/json.
> My server use this to get the data:
> $data = json_decode(file_get_contents('php://input'));
>
> The client-code is simpel, i don't select any encoding-formats etc.:
> new Ajax.Request('server.php',
> {
> method: 'post',
> parameters: JSON.stringify({
> method: 'foo::bar',
> params: [data],
> id: new Date().getTime()
> }), ...
Hello XP,
I'm not a network guy, but I imagine you may find that some users (i.e. those
using proxy servers, or those using certain browsers) may encounter problems
when attempting to post non-url encoded characters. In fact, it may not work
for anybody. Traditionally, setting up a scheme like this in php would simply
request php to build the data from the posted string:
<php>
$data = $_POST;
// where data then looks like the following, based on an ajax-posted
object run through Hash.toQueryString()
$data = array(
'method'=>'foo::bar',
'params'=>array('some data',array('some nested'=>'data')),
'id'=>'1123123123'
);
</php>
If you WOULD like to try sending JSON, you could override the original
prototype Hash.toQueryString method by defining it after inclusion of
prototype something like so:
Object.extend(Hash, {
toQueryString: function(obj) {
JSON.stringify(obj);
}
});
then, in the parameters, send a simple object like so:
new Ajax.Request('server.php',
{
method: 'post',
parameters: {
method: 'foo::bar',
params: data,
id: new Date().getTime()
}), ...
If you do try it, let us know what you find.
Regards,
Ken Snyder
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---