Is there a simple tutorial for this somewhere?
Ideally I'd like to have a textbox and a button, and when the user clicks the button, the textbox is sent to the server, which returns a value based on it.
The client then populates another textbox with the return value, but all without refreshing the page.
If it's possible, showing/hiding a loading gif would be awesome too.
I'm not finding any simple tutorials for how to do this, can anyone point me in the right direction?
Try googling for jQuery+AJAX.
There are lots of examples out there:
jQuery's Ajax method is your friend: http://api.jquery.com/category/ajax
HTML
CSS
jQuery
Working example: http://jsfiddle.net/G4uw6/
You would do it like this:
To walk you through the function, the first parameter
url
is set to the location of the resource you want to get a response from. Thetype
parameter sets the HTTP method used, it is most commonly set to eitherGET
(which is the default value) which appends any data being sent to the url orPOST
which appends any data being sent to the request header.data
is an object or string containing the data to be sent to the requested page, it can either be in object form{param1: 'value1',param2: 'value2'}
or as url encoded string"param1=value1¶m2=value2"
. Thesuccess
method is called when a response has been received from the server which was successful. ThebeforeSend
method is called before the request is sent and thecomplete
method is called when a response has been received from the server regardless of the success of the request.For more info, check out the Official jQuery API documentation of the jQuery.ajax() object