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 <[email protected]> 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=value1&key2=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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---