[ 4 posts ]

Jon Sword

  • Username: jsword
  • Joined: Wed Oct 05, 2011 8:16 pm
  • Posts: 10
  • Offline
  • Profile

DataSource.Get does not work for local URL

Post Posted: Wed Oct 05, 2011 9:09 pm
+0-
Hello,

I have been trying for several days to get DataSource.Get to work. I started off ambitiously and failed - so I slowly refined my prototype to a very simple variation of the example YUI3 DataTable + DataSource.Get + JSON Data and it still does not work.

The test code:
http://pastie.org/2647743

The dirty details:
I downloaded the JSON from query.yahooapis.com to a file called yql.php. I transformed it to a php script that sets a couple of headers and echos the JSON data when called (I removed an apostrophe from a text field to simplify quoting). When I download from my php script using my browser the resulting file is identical to the file retrieved from query.yahooapis.com (with the exception of the removed apostrophe and a timestamp embedded in the JSON). The php script does not interpret any of the query passed to it on the url.

These are the headers php sends:
Code:
        header("HTTP/1.1 200 OK");
        header('Content-type: application/json; charset=utf-8');
        header("Cache-Control: no-cache, must-revalidate");
        header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
        header("Pragma: no-cache");


The results:
When pointing the "source" to query.yahooapis.com it creates the table including the data.
When pointing the "source" to my yql.php it creates the table headers and displays no data.
In my server logs I can see the yql.php file is retrieved with HTTP "200" so I believe the file is being found and data is getting to DataSource.

I am entirely stumped and would appreciate any suggestions.
Regards,
Jon

Jon Sword

  • Username: jsword
  • Joined: Wed Oct 05, 2011 8:16 pm
  • Posts: 10
  • Offline
  • Profile

Re: DataSource.Get does not work for local URL

Post Posted: Thu Oct 06, 2011 4:48 pm
+0-
I have noticed references here http://yuilibrary.com/yui/docs/datasource/#get to the server supporting a "script callback parameter". I have no idea what this means. Can anyone tell me how I would check and/or implement this?

Might this be my problem?

Satyam

YUI Contributor

  • Username: Satyam
  • Joined: Tue Dec 09, 2008 12:34 am
  • Posts: 2016
  • Location: Sitges, Spain
  • GitHub: Satyam
  • Gists: Satyam
  • IRC: DevaSatyam
  • YUI Developer
  • Offline
  • Profile

Re: DataSource.Get does not work for local URL

Post Posted: Thu Oct 06, 2011 11:09 pm
+0-
Get creates a <script> tag that loads whatever comes from the given URL. Imagine you write that script tag yourself into the <head>. If that URL provides just data, it will be read, evaluated and, since it is not being assigned anywhere, discarded. Basically, imagine you do this:

<script>1</script>

That number one will be read, evaluated and discarded.

So, the callback parameter is the name of a function that would do something with the data. The data actually gets enclosed in a function call, like this:

<script>cbFunc(1)</script>

Now, the function cbFunc gets that 1 and may do something with it. The script datasource provides a callback for each call so it gets the data and can do something with it before it gets lost. It generates those callbacks dynamically so your server must use whichever the datasource generated in each call.

Alberto Santini

YUI Contributor

  • Offline
  • Profile

Re: DataSource.Get does not work for local URL

Post Posted: Thu Oct 06, 2011 11:54 pm
+0-
Hello Jon.

The snippet you pasted works correctly:
http://jsfiddle.net/R2XYS/

I suggest to double check the server response compared with yql one.

YQL returns the response in jsonp format as explained by Satyam.

See also "DataSource Get reading json response - very basic":
viewtopic.php?f=92&t=8685&p=27874


Hope that helps,
Alberto
  [ 4 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum