How to use get() Method in JQuery AJAX
In this article, I will explain use of get() Method in JQuery AJAX.
Query AJAX get() Method
- get() method request to Load URL document to open using AJAX HTTP GET request.
Syntax
$(selector).get(url,data,callback,dataType)
|
Parameter
- url: url is required parameter. A string containing the url to send the request to server.
- data: data is optional parameter. data to send to the server when request was found.
- callback: callback is the optional parameter. It is use to represents a function to be executed whenever he data is loaded successfully.
- type: type is the optional parameter. it is represents type of data to be returned to callback function: "xml", "html", "script", "json", "jsonp", or "text".
Example
The following example show the use of get() method.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("button").click(function () {
$.getJSON("demo_ajax_json.js", function (result) {
$.each(result, function (i, field) {
$("div").append(field + " ");
});
});
});
});
</script>
</head>
<body>
<h2>getJSON() Method Example</h2>
<button>Click for get JSON data</button>
<div></div>
</body>
</html>
|
Output
You may also want to read these related articles Click here
Ask Your Question
Got a programming related question? You may want to post your question here
Programming Answers here