Loading JSON Test Data

77 views
Skip to first unread message

CSchulz

unread,
Dec 3, 2011, 8:54:25 AM12/3/11
to google-we...@googlegroups.com
I'm wondering if there's a way to have a json file, hosted locally or online, where I can create a bunch of test data and then load it into my GWT app and parse it like a RequestBuilder call. I've been looking online for a way to do this and nothing seems to work. I then tried putting together a php script to return some json, and even though it works in the browser and returns a 200 status code in my Charles web proxy, in GWT it returns a status code 0 and doesn't give me any data. The php file was not hosted locally and I have the php content type set to application/json. If there's another way to load this json that would be nice. I don't want to have to create these json objects from scratch in GWT.

Alfredo Quiroga-Villamil

unread,
Dec 3, 2011, 9:22:04 AM12/3/11
to google-we...@googlegroups.com
To handle the response you have a few options:


You can read the JSON response and pretty easily map it to the JS Overlay Type you've defined describing the JSON structure.


Similar as 1) above, just even cooler. At least for me :)

Your comment:

"in GWT it returns a status code 0" ...

You are running into the SOP (Same Origin Policy) here.

There are a couple of alternatives:


b) You can send the call to your server (running on the same domain, making sure you don't violate none of the SOP rules, different port,etc..) and from there send a call to your remote server.

c) You can load the test data from your domain backend server and then test from there so you don't run into the SOP issue using either 1) or 2) mentioned above.

There are might be other options, those come to mind right now.

Regards,

Alfredo


On Sat, Dec 3, 2011 at 8:54 AM, CSchulz <csc...@acumeta.com> wrote:
I'm wondering if there's a way to have a json file, hosted locally or online, where I can create a bunch of test data and then load it into my GWT app and parse it like a RequestBuilder call. I've been looking online for a way to do this and nothing seems to work. I then tried putting together a php script to return some json, and even though it works in the browser and returns a 200 status code in my Charles web proxy, in GWT it returns a status code 0 and doesn't give me any data. The php file was not hosted locally and I have the php content type set to application/json. If there's another way to load this json that would be nice. I don't want to have to create these json objects from scratch in GWT.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/TMv9iuNq82MJ.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.



--
Alfredo Quiroga-Villamil

AOL/Yahoo/Gmail/MSN IM:  lawwton


CSchulz

unread,
Dec 3, 2011, 9:34:55 AM12/3/11
to google-we...@googlegroups.com
I already understand GWT JS Overlay Types. That's not the issue. 

I'm running the php script on a web server online, and I'm running the GWT project from my current machine, so they're not running on the same machine or same network. So I don't think that's the issue either.

Is there a way to just call the json file directly and then parse it? That would be ideal.

Alfredo Quiroga-Villamil

unread,
Dec 3, 2011, 9:39:20 AM12/3/11
to google-we...@googlegroups.com
If you read my previous post, I stated that you are crossing domains (SOP). That is your issue, hence your return of 0. To get around that, I listed two options at the bottom of my previous reply. That would allow you to reach your server. How you load JSON afterwards is up to you. I also stated two ways to load JSON. If you are familiar with JS Overlay Types then use that.

Regards,

Alfredo

--
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-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

CSchulz

unread,
Dec 3, 2011, 10:09:19 AM12/3/11
to google-we...@googlegroups.com
I was misunderstood on SOP and what that involved, but I think I understand that now. I don't understand why when I make a call to a remote server it works just fine, but when I make a call to a remote php file that returns json, it doesn't work.

I've tried using jsonprequestbuilder without success. I'm would think there would be an easier way to retrieve this data: http://coryschulz.com/data.json I'll keep playing with jsonprequestbuilder and see if I can get it to work.

Thomas Broyer

unread,
Dec 3, 2011, 10:12:17 AM12/3/11
to google-we...@googlegroups.com
JSONP, despite its name, is not JSON, it's JavaScript; it needs support on the server-side.
Reply all
Reply to author
Forward
0 new messages