PDA

View Full Version : What to pass back from JSON call


dudeshouse
07-24-2009, 05:01 PM
Hi,
Firstly I'd like to say I'm fairly new at this. I know ASP well, but php and advanced javascript phase me... On that note...
What I'm trying to do is pick apart a site I've been handed, which was put together using the Zend framework, which doesn't help my case at all as trying to pick that apart isn't fun at the best of times.
I'm trying to translate a Google map using JSON and php, into ASP. The whole site is being redeveloped, and being an ASP programmer, this is just how it is.
The call that is being made is as follows:
function getPossible(){

$("#console").text("Loading ... ");
// $.getJSON("/directory/query?border="+map.getBounds()+"&facilities="+selected_facilities,
$.getJSON("/pubs/directory-query.asp?border="+map.getBounds()+"&facilities="+selected_facilities,

function(data){
clearPubs();
$("#console").text("Loaded "+data.count + " pubs maching your criteria");
for(i in data){
if(data[i].id > 0 ){
var point = new GLatLng( parseFloat(data[i].lat),parseFloat(data[i].long));
if( data[i].id == selected_pub_id){
var marker = createFlashMarker(point,'<b>'+data[i].name+'</b><Br/>'+'<a href="'+data[i].link+'">view details</a><br />'+data[i].address+'<br />'+data[i].postcode +', '+ data[i].town_name + '<br /> phone:'+data[i].phone+'<br />',data[i].name + "");
}else{
var marker = createMarker(point,'<b>'+data[i].name+'</b><br/>'+'<a href="'+data[i].link+'">view details</a><br />'+data[i].address+'<br />'+data[i].postcode +', '+ data[i].town_name + '<br />phone:'+data[i].phone+'<br />',data[i].name + "");
}
map.addOverlay(marker);

}

}
});
}
I think I'm understanding most of this now.
You will see that I'm calling the .asp page now and it's then getting the data from the database.
What I'm failing at is how to pass it back to this call, so that it can be used by the function(data) part.
I've tried returning a created array, I've tried returning a string along the lines of "[id,1,long,53,lat,51....]" as well as using {} around it.
I tried the string approach as Zend seemed to be encoding the output this way.
If anyone can help, that would be great. At present, the console doesn't get past showing "Loading..." so I reckon it's something I'm doing wrong regarding passing the data back from the asp page.
Thanks in anticipation....
Glenn

rnd me
07-25-2009, 02:27 AM
my asp mini library (link is signature) includes a string serialize meths, toSource(), based on the JSON1 library.
if you have a jscript object in asp, it will basically turn it into JSON for you, like php's json_encode() function.

basically, you need to censor or escape any quotes, and wrap quotes around any string variables. String(something).toSource() in the above library will escape all the special chars, and add quotes to your string, making it safe for delivery though a script tag.

note that you may need to specify an older jscript version in the script tag to run it in aspx, but it can still run even today.

it's a javascript library, and the only way to run ecma3 compliant js on the server is with asp "classic", which nobody seems to do for some reason; it's all about vb and c#...

dudeshouse
07-27-2009, 02:04 PM
Cool, thanks for the reply.

I will try and take a look at it in the next couple of days and see if I can figure out what's happening. I'm still not certain about what format of data to return so that the rest of the function can deal with it, but will repost once I've looked in to it further.

Thanks again.