...

View Full Version : How to filter jquery results from google spreadsheets



usurper
01-07-2009, 10:21 PM
This is a bit of a noob question.

I'm trying to query some data from google spreadsheets using javascript.

This is the URL request


var url = 'http://spreadsheets.google.com/feeds/list'
+ '/' + param_ssKey + '/' + param_wsId + '/public/values' +
'?sq=category%3DselectedSearch&alt=json-in-script&callback=cm_loadMapJSON';

The problem is that 'selectedSearch' in the the above code (sq=category%3DselectedSearch) is a variable name and not a literal. The expression is expecting a literal. Is there some syntax that I need to apply to the selectedSearch variable to make this query work possible?

thanks

rnd me
01-08-2009, 03:26 PM
as far as javascript is concerned, category%3DselectedSearch is just a string primitive in the code.

you will need to know what param_ssKey and param_wsId are.

you can type those into firebug from the original page, and it will tell you the actual value of those variables.

usurper
01-08-2009, 03:40 PM
as far as javascript is concerned, category%3DselectedSearch is just a string primitive in the code.

you will need to know what param_ssKey and param_wsId are.

you can type those into firebug from the original page, and it will tell you the actual value of those variables.

Thanks. I don't think I explained it well. For example.. if I change the query to include category%3DRestaurants, it works fine. It returns all the records with the value 'Restaurants' in the category column. So there is no issue with the param variables.

What I would like to be able to do is use a variable(selectedSearch) in the place of 'Restaurants'.

The variable would contain a string literal that I retrieve from a form.

I.E. the user selects 'Restaurants' from a dropdown box. This value gets assigned to the variable selectedSearch and this in turn gets added to the sq expression.

thanks

rnd me
01-08-2009, 06:10 PM
if str was a string you got from a form:

"category%3DRestaurants" could be replaced by "category%3D"+encodeURIComponent(str);

usurper
01-08-2009, 10:41 PM
Thanks again.

I've tried this


'?sq=category%3D'+encodeURIComponent(selectedSearch)+&alt=json-in-script&callback=cm_loadMapJSON';

and this


'?sq="category%3D"+encodeURIComponent(selectedSearch)&alt=json-in-script&callback=cm_loadMapJSON';

still not working though. Can you spot anything? I've checked if selectedSearch is holding the right value

usurper
01-08-2009, 10:51 PM
got it

thanks a lot


'?sq=category%3D'+encodeURIComponent(selectedSearch)+'&alt=json-in-script&callback=cm_loadMapJSON';



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum