Re: Newbie Question on GWT/JSON

2009-01-05 Thread Reinier Zwitserloot

Whoops, forgot my footnote:

[1] http://www.ietf.org/rfc/rfc4627.txt

I don't know if that makes it official. I believe the official entity
that vets mime types is IANA, but on their site I couldn't quickly get
to an official list of recognized mime types. Still, if Doug Crockford
says the type is application/json, and almost everyone uses that,
that's the standard. That's how the internet works; standards bodies
can wax rhapsodic about whatever they fancy, but if no one does it,
it's not something you should be doing either, regardless of whether
or not its the 'official standard', so, there you have it.

Oh, and martykube: Be careful that your soul doesn't waft out the
window that is giving you that fresh air. As a general rule, if PHP is
a good fit for you, grails, rails, or django are usually an even
better fit.

On Jan 4, 11:48 pm, rakesh wagh rake...@gmail.com wrote:
 You probably got your answer by now. Think this way. JSON string is
 like any other string. The transport mechanism does not have to know
 weather it is json or text or number or binary or otherwise. With that
 said, you can use forms with get or post(knowing the advantages
 drawback of each will help you select the right mechanism) and simply
 posting it to your php page. In your php page, read the request
 parameters as if they were any other parameters.

 As a matter of fact you can even append the json string as part of
 your target page url with a variable name and expect the json string
 (with a hyperlink click) to reach its destination as expected.

 Good luck!
 Rakesh Wagh

 On Jan 3, 9:09 pm, Ian ikra...@gmail.com wrote:

  I am new to the Web application world; I am trying to encapsulate my
  set of data in a JSONObject, convert to string, and send it  (async
  POST) to a PHP page using GWT's RequestBuilder. GWT's tutorial
  discusses the trip from the server back to the client and not the
  other way around where I am unclear about.

  Do I need to set the header? Currently I set it to:
   builder.setHeader(Content-Type, application/x-www-form-
  urlencoded);

  However, this works fine as long as am sending
  key1=value1key2=values where I can retrieve variable via $_POST
  ['key1'] or $_POST['key2']

  But I am not sure how to send a JSON string where it can be retrieved
  in a php page. I have tried sending myvar=MyJsonString but cannot
  retrieve in my php page. How should $_POST reference the JSON object?

  Any clarification would be much appreciated.

  Thanks,

  Ian
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~--~~~~--~~--~--~---



Re: Newbie Question on GWT/JSON

2009-01-04 Thread Ian Petersen

On Sun, Jan 4, 2009 at 11:31 PM, Reinier Zwitserloot reini...@gmail.com wrote:
 JSON's mimetype is application/json (see [1] below).

You missed the [1] below part and my interest is piqued.  Is
application/json an officially accepted MIME type?

 Oh, PHP. Every single time someone posts a code snippet written in
 PHP, my aesthetic sense blows its brains out in sheer despair. And
 this one is up there, which is really saying something. I think its a
 conspiracy by the zend folks to make the inner child of developers
 worldwide die a little inside every time they come in contact with it.
 Sadistic bastards.

Too bad the truth can be so inflammatory

Ian

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~--~~~~--~~--~--~---



Re: Newbie Question on GWT/JSON

2009-01-04 Thread rakesh wagh

You probably got your answer by now. Think this way. JSON string is
like any other string. The transport mechanism does not have to know
weather it is json or text or number or binary or otherwise. With that
said, you can use forms with get or post(knowing the advantages
drawback of each will help you select the right mechanism) and simply
posting it to your php page. In your php page, read the request
parameters as if they were any other parameters.

As a matter of fact you can even append the json string as part of
your target page url with a variable name and expect the json string
(with a hyperlink click) to reach its destination as expected.

Good luck!
Rakesh Wagh

On Jan 3, 9:09 pm, Ian ikra...@gmail.com wrote:
 I am new to the Web application world; I am trying to encapsulate my
 set of data in a JSONObject, convert to string, and send it  (async
 POST) to a PHP page using GWT's RequestBuilder. GWT's tutorial
 discusses the trip from the server back to the client and not the
 other way around where I am unclear about.

 Do I need to set the header? Currently I set it to:
  builder.setHeader(Content-Type, application/x-www-form-
 urlencoded);

 However, this works fine as long as am sending
 key1=value1key2=values where I can retrieve variable via $_POST
 ['key1'] or $_POST['key2']

 But I am not sure how to send a JSON string where it can be retrieved
 in a php page. I have tried sending myvar=MyJsonString but cannot
 retrieve in my php page. How should $_POST reference the JSON object?

 Any clarification would be much appreciated.

 Thanks,

 Ian
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~--~~~~--~~--~--~---



Newbie Question on GWT/JSON

2009-01-03 Thread Ian

I am new to the Web application world; I am trying to encapsulate my
set of data in a JSONObject, convert to string, and send it  (async
POST) to a PHP page using GWT's RequestBuilder. GWT's tutorial
discusses the trip from the server back to the client and not the
other way around where I am unclear about.

Do I need to set the header? Currently I set it to:
 builder.setHeader(Content-Type, application/x-www-form-
urlencoded);

However, this works fine as long as am sending
key1=value1key2=values where I can retrieve variable via $_POST
['key1'] or $_POST['key2']

But I am not sure how to send a JSON string where it can be retrieved
in a php page. I have tried sending myvar=MyJsonString but cannot
retrieve in my php page. How should $_POST reference the JSON object?

Any clarification would be much appreciated.

Thanks,

Ian

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~--~~~~--~~--~--~---



Re: Newbie Question on GWT/JSON

2009-01-03 Thread Reinier Zwitserloot

Whatever possessed you to send the application/x-www-form-
urlencoded as mime type?

JSON is nothing like form-encoded. That's like sending your HTML as
image/jpeg just for kicks. Don't do that.

JSON's mimetype is application/json (see [1] below). If you want to
be nice, you should actually set that in the header (as follows:
Content-type: application/json; encoding=UTF-8  - note that JSON is
defined to be UTF-8 encoded, so you're just clarifying there, you
can't pick your own encoding).

And, yes, of course, in PHP you would have to get the entire request
body, instead of letting PHP try to parse it as form data. Possibly
PHP is presuming that the data IS form encoded when there is no header
at all. Is file_get_contents(php://input); really the only feasible
way to get the entire body in PHP?

Oh, PHP. Every single time someone posts a code snippet written in
PHP, my aesthetic sense blows its brains out in sheer despair. And
this one is up there, which is really saying something. I think its a
conspiracy by the zend folks to make the inner child of developers
worldwide die a little inside every time they come in contact with it.
Sadistic bastards.



On Jan 4, 6:52 am, Ian ikra...@gmail.com wrote:
 For those who might be facing a similar problem and others who might
 be interested in my previous question I have come up with an answer.
 First my disclaimer: the solution below may not be the proper one but
 it does work. Now on to the solution:

 On the GWT Client Side:

 JSONObject jObject = new JSONObject();
 jObject .put(propA, new JSONString(valA));
 jObject .put(...

 RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
 YOUR_PHP_URL);
 builder.sendRequest(jObject.toString(), new YourReponseHandler());

 Note that there is no setHeader.

 On the PHP side:

 Get the raw data instead of $_POST
 $jsonReq = file_get_contents(php://input);

 Decode the json request
 $request = json_decode($jsonReq);

 Cheers,
 Ian

 On Jan 3, 10:09 pm, Ian ikra...@gmail.com wrote:

  I am new to the Web application world; I am trying to encapsulate my
  set of data in a JSONObject, convert to string, and send it  (async
  POST) to a PHP page using GWT's RequestBuilder. GWT's tutorial
  discusses the trip from the server back to the client and not the
  other way around where I am unclear about.

  Do I need to set the header? Currently I set it to:
   builder.setHeader(Content-Type, application/x-www-form-
  urlencoded);

  However, this works fine as long as am sending
  key1=value1key2=values where I can retrieve variable via $_POST
  ['key1'] or $_POST['key2']

  But I am not sure how to send a JSON string where it can be retrieved
  in a php page. I have tried sending myvar=MyJsonString but cannot
  retrieve in my php page. How should $_POST reference the JSON object?

  Any clarification would be much appreciated.

  Thanks,

  Ian
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~--~~~~--~~--~--~---