Using Javascript to make parallel server requests THREDDS OPeNDAP - javascript

For the following THREDDS OPeNDAP server:
http://data.nodc.noaa.gov/thredds/catalog/ghrsst/L2P/MODIS_T/JPL/2015/294/catalog.html
I would like to note four Attributes of every file in there. The attributes are:
northernmost lattitude; easternmost lattitude; westernmost lattitude; southernmost lattitude. These can be found under the Global attributes under:
http://data.nodc.noaa.gov/thredds/dodsC/ghrsst/L2P/MODIS_T/JPL/2015/294/20151021-MODIS_T-JPL-L2P-T2015294235500.L2_LAC_GHRSST_N-v01.nc.bz2.html
At first I tried this with MATLAB. Problem is: all the netcdf files on the server are compiled to .bz2 files. This makes calling for the Global attributes take around 15 seconds (the server is extracting the file). I would like javascript to run these server requests parallel to save me time. In total I need 90,000 files.
Is there a way to code this using javascript?

You can use the THREDDS DAS service. DAS
Change the OPenDAP link you have above replacing the .html extension with .das
This is a small text file with metadata about the file which could be easily parsed with javascript and includes a section with the global attributes:
NC_GLOBAL {
. . .
Float32 northernmost_latitude 89.9942;
Float32 southernmost_latitude 66.9853;
Float32 easternmost_longitude -121.445;
Float32 westernmost_longitude 76.7485;
. . .
}
This metadata is cached by THREDDS and the above DAS link responds instantly.
Edit:
Re: the correct comments below, (cache exists only after the first request) one alternative might be to use the source data at the NASA JPL OPeNDAP Server (Hyrax): http://podaac-opendap.jpl.nasa.gov/opendap/allData/ghrsst/data/L2P/MODIS_T/JPL/
My browser only tests (i.e. subjective) seem to show that a random DAS responses are quicker, than 15 seconds.
http://podaac-opendap.jpl.nasa.gov/opendap/allData/ghrsst/data/L2P/MODIS_T/JPL/2015/294/20151021-MODIS_T-JPL-L2P-T2015294084500.L2_LAC_GHRSST_N-v01.nc.bz2.das

Related

Simple online web game crash eventually

Background:
I am making a simple game in PHP, JavaScript and HTML for the web. A player control movements of a box on the screen, and see others fly around with their boxes.
I have the following files, that I upload to my domain via a hosting company:
index.html: a file with some buttons (eg. to start the game) and frames (for putting boxes in).
server.php: PHP script that receives messages from client, performs reads/writes to a database, echoes (using echo) boxes from database to the client. Does not echo the box of the player the message came from.
database.txt: a JSON text file containing data of players and the next free ID number. When empty it looks like this: {"players":[], "id": 1}. players contain objects with values such as ID, position and rotation.
script.js: JavaScript file with script to send/receive messages, display data from messages etc. Linked to index.html. Moves your box.
A screenshot, two players in movement:
Problem: The game crashes, always. Sooner or later. This is what happens:
Client recevies player data from server.php, everything is fine. This could be for 10 seconds or up to some minutes.
The data starts to falter, the message sometimes is null instead of actual data.
The data recevied is always null. The database file is now {"players":null,"id":5}. (The "id" could be any number, does not have to be 5).
Picture of data flow, printing of players from database. Two players. Before this screenshot lots of rows with valid data. Then as seen two null messages. Then after a while null forever.
I am not completely sure where the problem is, but I am guessing it has to do with my read/write in server.php. I feels like a lot of player movement makes the program more likely to crash. Also how often the program sends data affetcs.
Code Piece 1: This is code from server.php, that writes to the database. I have some sort of semaphore (the flock( ... ) ) to prevent clients from reading/writing at the same time (causing errors). I have an other function, read, which is very similar to this. Possible problems here:
The semaphore is incorrect.
The mode for fopen() is incorrect. See PHP docs. The mode w is for write. The tag b is for "If you do not specify the 'b' flag when working with binary files, you may experience strange problems with your data ...".
Something weird happening because I use read() in my writing function?
Code:
// Write $val to $obj in database JSON
function write($obj,$val){
$content = read();
$json = json_decode($content);
$json->{$obj} = $val; // eg. $json->{'id'} = 5;
$myfile = fopen("database.txt", "wb") or die("Unable to open file!");
if(flock($myfile, LOCK_EX|LOCK_NB)) {
fwrite($myfile,json_encode($json));
flock($myfile, LOCK_UN);
}
fclose($myfile);
}
Code Piece 2: This is my code to send data. It is called via a setInterval(). In script.js:
// Send message to server.php, call callback with answer
function communicate(messageFunc,callback){
var message = messageFunc();
if (window.XMLHttpRequest) {
var xmlhttp=new XMLHttpRequest();
}
xmlhttp.onreadystatechange= function() {
if (this.readyState==4 && this.status==200) {
callback(this.responseText);
}
}
xmlhttp.open("GET","server.php?msg="+message,true);
xmlhttp.send();
}
This is my code to receive data, in server.php: $receive = $_GET["msg"].
My current work of solving
This is what I have done so far, but nothing has changed:
Added mode b to fopen().
Added flock() to read/write functions in server.php.
Much reworking on script.js, I would say it looks/works very clean.
Check memory_get_peak_usage(), and check with the hosting company for memory limits. Should be no problem at all.
Looked at PHP garbage collecting and gc_enable() (I don't know why that would change anything).
Lots of testing, looking at the data flow.
Crying.
Conclusion: Is this type of application what PHP is for? What do you think is wrong? If you want more code/info I provide. Thank you very much.
Here is the root of your problem:
$myfile = fopen("database.txt", "wb") or die("Unable to open file!");
Note the behavior of the w open mode (emphasis mine):
Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
This happens before you lock the file. What's happening is that between this fopen() call and the following flock() call, the file's content is zero length, and a reader is coming along during that time and reading the empty file.
Why doesn't this cause an error in PHP when you parse the empty string as JSON? Because json_decode() is defective, and returns null when the input is not valid JSON rather than throwing an exception. Nevermind that the string "null" is valid JSON -- json_decode() gives you no way to differentiate between the cases of valid input representing the null value and invalid input. If json_decode() actually threw an exception or triggered a PHP error (don't ask me why two error-signalling mechanisms are necessary in PHP), you would have a fantastic point to start debugging to figure out why the file is empty, and you might have solved this problem by now!
... sigh ...
PHP's "design" gives me headaches. But I digress.
To fix this whole problem, change the open mode to "cb" and ftruncate($myfile, 0) after you successfully acquire the lock.
Note the behavior of the c mode, which actually specifically mentions the approach you are using (emphasis mine):
Open the file for writing only. If the file does not exist, it is created. If it exists, it is neither truncated (as opposed to 'w'), nor the call to this function fails (as is the case with 'x'). The file pointer is positioned on the beginning of the file. This may be useful if it's desired to get an advisory lock (see flock()) before attempting to modify the file, as using 'w' could truncate the file before the lock was obtained (if truncation is desired, ftruncate() can be used after the lock is requested).

Using combination of JSON.stringify and encodeURIComponent

So I hava a JSON stored in a variable
var x = '{"time":"Friday, January 15, 2016 9:13 PM","keywords":"social","tweets_people":[{"text":"#FreeformTV I want to see what my social DNA looks like! #FreeformLaunch","username":"bbjeagle","user_image":"http://pbs.twimg.com/profile_images/681285613526515712/H6aB4gS__normal.jpg","timestamp":"2016-01-15T15:42:59.000Z","display_name":"JOY","language":"en","tweet_id":"688023580240670720","location":"united_states","location_details":{"country":"united_states","type":"country"},"retweet_count":0,"reach":531,"favorite_count":0,"sentiment":84,"entities":{}},{"text":"#IBM Scoops Up IRIS Analytics Fraud Detection Firm https://t.co/6oisTfWGNq #technology #enterprise #social #tc","username":"chriswrighttech","user_image":"http://pbs.twimg.com/profile_images/577224176542445568/1N2FMNHV_normal.jpg","timestamp":"2016-01-15T15:42:55.000Z","display_name":"Chris Wright","language":"en","tweet_id":"688023567221534721","location":null,"location_details":null,"retweet_count":0,"reach":458,"favorite_count":0,"sentiment":-50,"entities":{"urls":[{"display_url":"goo.gl/fb/weklj1","expanded_url":"http://goo.gl/fb/weklj1","url":"https://t.co/6oisTfWGNq"}]}},{"text":"Handbook of Statistical Modeling for the Social and Behavioral Sciences https://t.co/qCbResQLzK https://t.co/sLf2uhhUQd","username":"allwood_mary","user_image":"http://pbs.twimg.com/profile_images/653044576501035008/VWEwjp_N_normal.jpg","timestamp":"2016-01-15T15:42:49.000Z","display_name":"Mary Allwood","language":"en","tweet_id":"688023541023924227","location":null,"location_details":null,"retweet_count":0,"reach":52,"favorite_count":0,"sentiment":34,"entities":{"urls":[{"display_url":"uae-trip.info/p/tr/?query=ht…","expanded_url":"http://uae-trip.info/p/tr/?query=http://rover.ebay.com/rover/1/711-53200-19…=2&toolid=10039&campid=5337597384&item=151951539608&vectorid=229466&lgeo=1","url":"https://t.co/qCbResQLzK"}],"photo":[{"display_url":"pic.twitter.com/sLf2uhhUQd","expanded_url":"http://twitter.com/allwood_mary/status/688023541023924227/photo/1","type":"photo","media_url":"http://pbs.twimg.com/media/CYxZw96WsAAzzvk.jpg","resolution":{"w":242,"h":400,"resize":"fit"},"url":"https://t.co/sLf2uhhUQd"}]}},{"text":"Philasmicos R5 CRM (Standard) #Business Social Networking #Mac App... https://t.co/88YCSejyyE #socialnetworking","username":"marac00per","user_image":"http://pbs.twimg.com/profile_images/509110528208142336/Ah4ZC3vh_normal.jpeg","timestamp":"2016-01-15T15:42:42.000Z","display_name":"Mara Cooper","language":"en","tweet_id":"688023510111916032","location":"miami","location_details":{"country":"united_states","city":"miami","state":"florida","type":"city"},"retweet_count":0,"reach":33649,"favorite_count":0,"sentiment":0,"entities":{"urls":[{"display_url":"goo.gl/fb/7hwwhZ","expanded_url":"http://goo.gl/fb/7hwwhZ","url":"https://t.co/88YCSejyyE"}]}}],"tweets_media":[{"text":"The Peach app is dead, but it taught us this about social media: https://t.co/0IJsSnb2z2 https://t.co/iqu71DKk4L","username":"NewRepublic","user_image":"http://pbs.twimg.com/profile_images/631195731756388352/rXgYnC9S_normal.jpg","timestamp":"2016-01-15T15:40:22.000Z","display_name":"New Republic","language":"en","tweet_id":"688022921747533824","location":"washington","location_details":{"country":"united_states","state":"washington","type":"state"},"retweet_count":0,"reach":139506,"favorite_count":0,"sentiment":35,"entities":{"urls":[{"display_url":"bit.ly/234xz4y","expanded_url":"http://bit.ly/234xz4y","url":"https://t.co/0IJsSnb2z2"}],"photo":[{"display_url":"pic.twitter.com/iqu71DKk4L","expanded_url":"http://twitter.com/NewRepublic/status/688022921747533824/photo/1","type":"photo","media_url":"http://pbs.twimg.com/media/CYxZM7FWMAMxrSz.jpg","resolution":{"w":1024,"h":532,"resize":"fit"},"url":"https://t.co/iqu71DKk4L"}]}},{"text":"FG will ensure social welfare for the poor – Osinbajo https://t.co/KDwyJnbAgj via #todayng https://t.co/BPpQ7GE4Gi","username":"NigeriaNewsdesk","user_image":"http://pbs.twimg.com/profile_images/559635895909752832/5m7oAlGi_normal.png","timestamp":"2016-01-15T15:39:37.000Z","display_name":"Nigeria Newsdesk","language":"en","tweet_id":"688022736917118980","location":null,"location_details":null,"retweet_count":2,"reach":1070269,"favorite_count":0,"sentiment":0,"entities":{"urls":[{"display_url":"today.ng/news/national/…","expanded_url":"https://www.today.ng/news/national/66295/fg-will-ensure-social-welfare-for-the-poor-osinbajo?utm_source=dlvr.it_nnd&utm_medium=twitter","url":"https://t.co/KDwyJnbAgj"}],"photo":[{"display_url":"pic.twitter.com/BPpQ7GE4Gi","expanded_url":"http://twitter.com/NigeriaNewsdesk/status/688022736917118980/photo/1","type":"photo","media_url":"http://pbs.twimg.com/media/CYxZCKsWYAI0NZw.jpg","resolution":{"w":1024,"h":806,"resize":"fit"},"url":"https://t.co/BPpQ7GE4Gi"}]}},{"text":"Building your personal brand on social media is as much about listening as talking. https://t.co/U8VwyRYgD6 https://t.co/1qes1tfVMB","username":"FT","user_image":"http://pbs.twimg.com/profile_images/466972537704824832/eflEColL_normal.png","timestamp":"2016-01-15T15:09:50.000Z","display_name":"Financial Times","language":"en","tweet_id":"688015237958774784","location":null,"location_details":null,"retweet_count":0,"reach":2190381,"favorite_count":0,"sentiment":35,"entities":{"urls":[{"display_url":"on.ft.com/234vi9l","expanded_url":"http://on.ft.com/234vi9l","url":"https://t.co/U8VwyRYgD6"}],"photo":[{"display_url":"pic.twitter.com/1qes1tfVMB","expanded_url":"http://twitter.com/FT/status/688015237958774784/photo/1","type":"photo","media_url":"http://pbs.twimg.com/media/CYxSNpKWMAArwFh.jpg","resolution":{"w":600,"h":338,"resize":"fit"},"url":"https://t.co/1qes1tfVMB"}]}},{"text":"Who has decided that women cannot go in?: Ranjana Kumari, Director, Centre for Social Research on #SabrimalaRow #LRC_NDTV","username":"ndtv","user_image":"http://pbs.twimg.com/profile_images/570440108424171520/QuGYd7jH_normal.png","timestamp":"2016-01-15T14:46:17.000Z","display_name":"NDTV","language":"en","tweet_id":"688009314565550080","location":"india","location_details":{"country":"india","type":"country"},"retweet_count":15,"reach":5824509,"favorite_count":6,"sentiment":0,"entities":{}}],"topUsers":[["FreeformTV",678,"100%"],["AsMickymouse82",141,"-100%"],["ILoveMyDinoMatt",120,"0%"],["CloudataNow",79,"12%"],["TheSocialMs",79,"100%"],["mhsowrove",75,"100%"],["TSM_B2B",70,"100%"],["ExploreWeb2dot0",61,"-4%"],["Go2WebMarketing",61,"-4%"],["dreckbaerfrau",58,"100%"]],"locations":[["london",523],["new_york",321],["chicago",238],["los_angeles",204],["toronto",156],["kota",152],["atlanta",129],["miami",121],["mumbai",106],["boston",104]],"time_series_mentions":{"14/01/2016_15:43":1501,"14/01/2016_16:43":1592,"14/01/2016_17:43":1692,"14/01/2016_18:43":1477,"14/01/2016_19:43":1537,"14/01/2016_20:43":1864,"14/01/2016_21:43":1313,"14/01/2016_22:43":1448,"14/01/2016_23:43":1498,"15/01/2016_00:43":1289,"15/01/2016_01:43":1094,"15/01/2016_02:43":1313,"15/01/2016_03:43":1337,"15/01/2016_04:43":1075,"15/01/2016_05:43":1069,"15/01/2016_06:43":1053,"15/01/2016_07:43":808,"15/01/2016_08:43":844,"15/01/2016_09:43":524,"15/01/2016_10:43":973,"15/01/2016_11:43":1148,"15/01/2016_12:43":1313,"15/01/2016_13:43":1272,"15/01/2016_14:43":1277},"time_series_impressions":{"14/01/2016_15:43":9631791,"14/01/2016_16:43":24597649,"14/01/2016_17:43":42674232,"14/01/2016_18:43":61093552,"14/01/2016_19:43":70688408,"14/01/2016_20:43":47669000,"14/01/2016_21:43":24028898,"14/01/2016_22:43":76327602,"14/01/2016_23:43":50294599,"15/01/2016_00:43":74220157,"15/01/2016_01:43":45603520,"15/01/2016_02:43":29450814,"15/01/2016_03:43":46223938,"15/01/2016_04:43":15439446,"15/01/2016_05:43":19868983,"15/01/2016_06:43":82828364,"15/01/2016_07:43":98291003,"15/01/2016_08:43":11781541,"15/01/2016_09:43":8872385,"15/01/2016_10:43":4314408,"15/01/2016_11:43":14093326,"15/01/2016_12:43":10846241,"15/01/2016_13:43":8302175,"15/01/2016_14:43":18581107},"time_series_sentiment":{"14/01/2016_15:43":60,"14/01/2016_16:43":67,"14/01/2016_17:43":55,"14/01/2016_18:43":69,"14/01/2016_19:43":69,"14/01/2016_20:43":61,"14/01/2016_21:43":61,"14/01/2016_22:43":58,"14/01/2016_23:43":54,"15/01/2016_00:43":61,"15/01/2016_01:43":68,"15/01/2016_02:43":60,"15/01/2016_03:43":59,"15/01/2016_04:43":57,"15/01/2016_05:43":50,"15/01/2016_06:43":70,"15/01/2016_07:43":70,"15/01/2016_08:43":61,"15/01/2016_09:43":73,"15/01/2016_10:43":66,"15/01/2016_11:43":68,"15/01/2016_12:43":70,"15/01/2016_13:43":66,"15/01/2016_14:43":67},"relatedTopics":[["#Waze",1745,-76.9],["#Freeformtv",1229,100],["#Freeformlaunch",1215,100],["#Gopdebate",693,-14.1],["#Social",668,45.2],["#Arsenal",493,-99.2],["#Elnennym",490,-100],["#Socialmedia",364,66.4],["#Marketing",261,62.2],["#Realdonaldtrump",236,69],["#Gurmeetramrahim",223,100]],"media":{"mentions":145,"impressions":230059822,"sentiment":"20%"},"people":{"mentions":30311,"impressions":895723139,"sentiment":"25.2%"}}';
I know this is avalid JSON (check here)
Now when I try to pass it to encodeURIComponent() to make it URL Safe, it doesn't encode it properly. I don't know why is it happening.
I want to pass this JSON to a PHP file from which i want to genrate a Excel file (genrated using this JSON data) using PHPExcel. I am doing this so that I can redirect the user to the php page passing this JSON as a GET parameter and which will download the file (as default behaviour of PHPExcel is it stores the file in filesystem) directly to the client without storing it to the filesystem.
By the way is it doable using AJAX, making an AJAX call to the PHP file passing this JSON as a POST data and, the PHP file builds EXCEL and respond with the excel file without uploading it to the server so that it can be directly downloaded to the client.
Your string is 8951 long before encoding, read this post to see why your GET query fails. Change your Ajax call to POST and that will work.
// x is not a string anymore, but a JSON object
var x= {"time":"Friday, January 15, 2016 9:13 PM", .... } ;
$.post ('myurl.php', x, function (ret, status) { ... }) ;

How to display 100K XML based DOM data on a JSP client page?

I need some help in understanding what to do next.
I need to write a web based search function to find medical records from an XML file.
The operator can enter either part or all of a patient name and Hit Search on the JSP web page.
The server is suppose to then return a list of possible patient names with the opportunity for the operator to go to next page until a possible patient is found. They can then select the person and view more details.
On the Server side
I have an XML file with about 100,000 records. There are five different types of records in the file. (This is roughly about 20,000 x 5 = 100,000).
I have a java class to source the xml file and create a DOM to traverse the data elements found on the file.
-- XML File Begin
100k - XML file outline
<hospital>
<infant key="infant/0002DC15" diagtype="general entry" mdate="2015-02-18">
<patient>James Holt</patient>
<physician>Michael Cheng</physician>
<physician>David Long</physician>
<diagnosisCode>IDC9</diagnosisCode>
..
</infant>
<injury key="injury/0002IC15" diagtype="general entry" mdate="2015-03-14">
<patient>Sara Lee</patient>
<physician>Michael Cheng</physician>
<diagnosisCode>IEC9</diagnosisCode>
..
</injury>
<terminal key="terminal/00X2IC15" diagtype="terminal entry" mdate="2015-05-14">
<patient>Jason Man</patient>
<physician>John Hoskin</physician>
<diagnosisCode>FEC9</diagnosisCode>
<diagnosisCode>FXC9</diagnosisCode>
..
</terminal>
<aged key= xxxx ... >
...
</aged>
<sickness key= xxxx ... >
...
</sickness>
</hospital>
approx 5 ( )x 20,000 = 100K records.
Key and patient are the only mandatory fields. The rest of the elements are Optional or multiple elements.
-- XML File End
Here is where I need help
Once I have the DOM how do I go forward in letting the client know what was found in the XML file?
Do I create a MAP to hold the element node links and then forward say 50 links at a time to the JSP and then wait to send some more links when the user hits next page?
Is there an automated way of displaying the links, either via a Java Script, Jquery, XSLT or do I just create a table in HTML and place patient links inside the rows? Is there some rendering specific thing I have to do in order to display the data depending on the browser used by client?
Any guidance, tutorials, examples or books I can refer to would be greatly appreciated.
Thank you.
I don't know an automatic way to match the type in jQuery, but you can test the attributes, something like verify if a non optional attribute in the object is present:
// Non optional Infant attribute
if(obj.nonOptionalAttribute) {
// handle Infant object
}
Or you may add an attribute to differentiate the types (something like a String or int attribute to test in your Javascript).
if(obj.type == 'infant') {
// handle Infant object
}
#John.west,
You can try to bind the XML to a list of objects (something like Injure implements MyXmlNodeMapping, Terminal implements MyXmlNodeMapping, Infant implements MyXmlNodeMapping and go on and have a List) to iterate and search by the value at the back end or you can pass this XML file to a Javascript (if you are using jQuery you can use a get or a post defining the result type as XML) and iterate over the objects to find what the user is trying to find...
Your choice may be based on the preference to use processor time in the server side or in the client side...

Possible to dump AJAX content from webpage?

I would like to dump all the names on this page and all the remaining 146 pages.
The red/orange previous/next buttons uses JavaScript it seams, and gets the names by AJAX.
Question
Is it possible to write a script to crawl the 146 pages and dump the names?
Does there exist Perl modules for this kind of thing?
You can use WWW::Mechanize or another Crawler for this. Web::Scraper might also be a good idea.
use Web::Scraper;
use URI;
use Data::Dump;
# First, create your scraper block
my $scraper = scraper {
# grab the text nodes from all elements with class type_firstname (that way you could also classify them by type)
process ".type_firstname", "list[]" => 'TEXT';
};
my #names;
foreach my $page ( 1 .. 146) {
# Fetch the page (add page number param)
my $res = $scraper->scrape( URI->new("http://www.familiestyrelsen.dk/samliv/navne/soeginavnelister/godkendtefornavne/drengenavne/?tx_lfnamelists_pi2[gotopage]=" . $page) );
# add them to our list of names
push #names, $_ for #{ $res->{list} };
}
dd \#names;
It will give you a very long list with all the names. Running it may take some time. Try with 1..1 first.
In general, try using WWW::Mechanize::Firefox which will essentially remote-control Firefox.
For that particular page though, you can just use something as simple as HTTP::Tiny.
Just make POST requests to the URL and pass the parameter tx_lfnamelists_pi2[gotopage] from 1 to 146.
Example at http://hackst.com/#4sslc for page #30.
Moral of the story: always look in Chrome's Network tab and see what requests the web page makes.

Does JSONP impose some size limit on the response?

I have implemented a simple PHP script to provide JSONP support for a set of JSON files I want to be accessible via cross-domain requests.
Here it is:
<?php
$jsonFile = $_GET['resource'] . ".json";
$fh = fopen($jsonFile, 'r');
$jsonData = fread($fh, filesize($jsonFile));
fclose($fh);
$jsonData = trim($jsonData);
header("Content-type: application/json");
echo $_GET['callback'] . '(' . $jsonData . ');';
?>
This works great when I type the url in manually.
If my URL is something like:
http://mywebserverdotcom/jsonp/data.php?resource=jsondata&callback=processJsonData
I see the response in the form of:
processJsonData([{"record_id":"317", ...}]);
and my data is complete and everything looks good.
However, when I try this using the following method in my HTML/JS:
1) I added a <script> element at the bottom of my HTML file with the URL above
2) Implemented a JS file with the callback function
I get an error. I used Web Inspector to see the error, and it shows an error on the callback, and it looks like the callback is cut off at about 200 characters or so (I didn't count) characters into the response, so the response is now:
processJsonData([{"record_id":"317", ...
The data is cut off, so the JSON format is messed up and there is no closing ); at the end of the function call, which creates an error. The error is: processJsonData variable not found.
So... Either I'm just doing this all wrong, OR there is some size limit in the response size allowed using a JSONP callback via the script element, OR something else I'm not thinking of....
Any help much appreciated!
Thanks
No, nothing about using JSONP should be limiting the size of your response. As far as the HTTP transport layer is concerned you are just sending some text data from the server to the client; it doesn't really care what that text data is or how it is structured internally.
Probably the issue is somewhere in the server-side code. Can you post the PHP you are using?
Make sure your JSONP response script is included after your script containing the callback function. The error message seems to indicate you had the script tags out of order. Your script tags should be ordered like this:
<script type="text/javascript" src="myscript.js" />
<script type="text/javascript" src="jsonprequest.php?callback=processJsonData&arg=1" />
A script tag's JavaScript is not executed until all previous scripts have executed. When your JSONP request script executes, it expects the handler to already exist. But if your script containing the handler isn't included until after the JSONP script, that is too late.
Here's a sampling of the data. I've left in the callback at the front. This is just part of the data, so the ending ]); are not included. It's public data. I know it's valid JSON because I'm using the exact same file using Ajax instead of JSONP to load it from my local machine and it works fine. It's only when accessing via this JSONP/PHP script from a remote server that it fails with the error. The exact error message is:
ReferenceError: Can't find variable: callback
and the location of the error is data.php:1 which is my remote PHP script.
callback([{"record_id":"317","artist":"Vern Luce","title":"Untitled","date":"1983","medium":"Painted steel","discipline":"sculpture","dimensions":"a: 93 \" x 40 \" x 64 \", b: 76.5 \" x 31 \" x 29 \", c: 48.5 \" x 85 \" x 20 \"","funding_source":"CETA","location":"MacLeay Park","street":"NW 29th Ave and Upshur St","city":"Portland","state":"OR","zipcode":"","lat":"45.535999799999999","lng":"-122.7110045","description":"Three geometric abstract steel sculptures are placed in a raised landscaped area in and located directly south of the Thurman Street Bridge. In siting the work, the artist wanted the sculptures to respond both to the surrounding greenspace (thus, the bright red color) and to the broad horizontal expanse of the Thurman Street bridge (thus, the vertical nature of the sculptures). At the time the pieces were installed, Vern Luce lived near Lower MacLeay Park and selected the site both for its visual beauty and its proximity to his home.\n\nProject History\nThe Comprehensive Education Training Act of the early 70's provided grants to a number of Portland artists that enabled them to create artwork. As a result, over 500 works by 52 artists became part of the City of Portland's collection, providing a rich and diverse history of art in Portland. Aside from Lower MacLeay Park, two other Portland parks feature permanent sculptures acquired through this program: a sculpture by Bruce West in Lair Hill Park and a piece by Jerry Allen in Peninsula Park.","image_url":"http:\/\/data.racc.org\/pa_inventory\/0240\/0240thumb.jpg","detail_url":"http:\/\/racc.org\/public-art\/search\/?recid=317.192","date_modified":"2010-07-19 00:00:00"},{"record_id":"359","artist":"Bruce West","title":"BW1","date":"1978","medium":"Cor-ten steel","discipline":"sculpture","dimensions":"6' x 30' x 20'","funding_source":"CETA 1976-77","location":"Lair Hill Park","street":"3000 SW Barbur Blvd","city":"Portland","state":"OR","zipcode":"97201","lat":"45.501570100000002","lng":"-122.68130650000001","description":"","image_url":"http:\/\/data.racc.org\/pa_inventory\/0098\/0098thumb.jpg","detail_url":"http:\/\/racc.org\/public-art\/search\/?recid=359.185","date_modified":"2010-12-29 00:00:00"},{"record_id":"362","artist":"Jerry Allen","title":"Disc #4","date":"1979","medium":"Cast silicon bronze","discipline":"sculpture","dimensions":"diameter: 4 1\/2'","funding_source":"CETA 1977-78","location":"Peninsula Park","street":"6222 N. Albina Avenue","city":"Portland","state":"OR","zipcode":"97217","lat":"45.568221899999998","lng":"-122.6748716","description":"","image_url":"http:\/\/data.racc.org\/pa_inventory\/0102\/0102thumb.jpg","detail_url":"http:\/\/racc.org\/public-art\/search\/?recid=360.55","date_modified":"2010-03-12 00:00:00"},

Categories