Jquery Ajax Get Data

Posted on  by admin
The jQuery get() method sends asynchronous http GET request to the server and retrieves the data.

Parameters Description: .

url: request url from which you want to retrieve the data . data: data to be sent to the server with the request as a query string .

callback: function to be executed when request succeeds .

The following example shows how to retrieve data from a text file.

In the above example, first parameter is a url from which we want to retrieve the data.

Here, we want to retrieve data from a txt file located at mydomain.com/data.txt. Please note that you don't need to give base address.

Internally, jQuery get() method calls ajax() method only. Visit james.padolsey.com/jquery and search for get() method to see the source code.

The second parameter is a callback function that will be executed when this GET request succeeds.
This callback function includes three parameters data, textStatus and jQuery wrapper of XMLHttpRequest object.
1

Data contains response data, textStatus contains status of request and jqXHR is a jQuery XMLHttpRequest object which you can use for further process.

The following example shows how to retrieve JSON data using get() method.

Rory McCrossanRory McCrossan
319k1

We have specified name parameter with value 'Steve' in the JSON format. So now, the request url would look like http://mydomain.com/jquery/getjsondata?name=Steve .

The third parameter is a callback function that will be executed when this GET request succeeds.

The jQuery getJSON() method sends asynchronous http GET request to the server and retrieves the data in JSON format by setting accepts header to application/json, text/javascript.

This is same as get() method, the only difference is that getJSON() method specifically retrieves JSON data whereas get() method retrieves any type of data.

Not the answer you're looking for? Browse other questions tagged jqueryajaxasp.net-mvcforms or ask your own question.