views:

119

answers:

3

Ok, a great example of what I am trying to achieve is at Google Translate. The URL: http://translate.google.com/#en|es|this is what I am trying to do makes a GET request using this URL: http://translate.google.com/translate_a/t?client=t&text=this%20is%20what%20I%20am%20trying%20to%20do&sl=en&tl=es&otf=1&pc=0

I'm not trying to do the real-time aspect. Right now I have the basic AJAX stuff working (using jQuery and .getJSON()), makes a GET request, Python function does stuff and returns JSON data, the callback function in .getJSON handles it and updates the page dynamically.

So how would I

  1. Make a customized URL that will contain the information from form elements that I would need in processing.
  2. Make this URL, when clicked on or put in an address bar, make the appropriate GET request.
  3. Have the function that is returning JSON, be able to return it and have the content updated dynamically on the page.

edit: Ok, I guess an easier way of asking this is, the server side Python function I have handles the GET requests. It returns the data back as JSON, this works ok if the request is made by .getJSON() because it has the callback to handle updating the HTML on the page. But, say I want to link to a certain query, ex: http://mysite.com/q?s=hello&r=3 if that URL is put in the address bar, the GET request will be made and it will return JSON (as it should), but since the .getJSON() didn't make that request, the callback doesn't fire.

So how would I have it so I could use that link but have it handle it as if the .getJSON() had requested it?

A: 

Hey, you can make a customized URL by getting the values of the input fields you wish and then just concatenate this with you url.

$.getJSON("http://translate?lang=" + $(".lang").attr("value") + "&text=bla");

i just simplized here the usage to show you how it works. if this don't helps you, it would be great if you provide additional information.

for the other things like events (clicking on a button) please read the jQuery documentation.

Joschua
+1  A: 

What you're looking for is JQuery's Serialization functionality.

jcm
A: 

Please see http://whiffdoc.appspot.com/docs/W1100_1400.calc for a tutorial that describes how to do stuff like this.

Aaron Watters