If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
jQuery में $.get() method का use GET Type की request send करने के लिए किया जाता है। jQuery AJAX में server से communicate करने का यह सबसे आसान तरीका है।
get() method use करने से पहले यह समझते हैं कि Request Type क्या होता है
Basically request दो तरह की होती है , GET & POST .
GET : GET Request के साथ हमेशा Query String Form ('key = value ') में ही data send कर सकते हैं , जो कि URL में append होता है। इसे कोई भी देख सकता है। और limited data ही send कर सकते हैं। इसलिए mostly इसका use Data retrieve करने के लिए किया जाता है।
POST : POST Request का use भी हम data retrieve करने के लिए कर सकते है , लेकिन POST Type के साथ submit किया गया data कोई देख नहीं पाता।
$.get('/path/to/file', function(reponse, status) { /*optional stuff to do after success */ });
जिसमे callback function तब run होता है , जब request complete हो जाती है और response ready होता है। ये request response और status return करता है।
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery $.get() Method </title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<p class="target_elm">Click bellow buttons button to see result.</p>
<p>
<button class="send_request">Send Request</button>
</p>
<script type="text/javascript">
window.onload = function(){
/*check if jquery working*/
if(window.jQuery){
$(".send_request").click(function(event) {
/*send request with query string data*/
$.get('handle_request.php?fname=Rahul&lname=Rajput', function(response, status, xhr)
{
/*set resturn data*/
$(".target_elm").html(response);
/*see in console , what's coming from server*/
console.log('response', response);
console.log('status', status);
console.log('xhr', xhr);
});
});
}
}
</script>
</body>
</html>
File : handle_request.php
<?php
echo 'Full Name : '.$_GET['fname']. ' '. $_GET['lname'];
?>
ऊपर दिए गए example को run करने से पहले Browser Console open करले जिससे आप Output देख सकें।
Hi ! My name is Rahul Kumar Rajput. I'm a back end web developer and founder of learnhindituts.com. I live in Uttar Pradesh (UP), India and I love to talk about programming as well as writing technical tutorials and tips that can help to others.
Get connected with me. :) LinkedIn Twitter Instagram Facebook