How to use Get Request with Ajax in PHP

03-Apr-2023

.

Admin

How to use Get Request with Ajax in PHP

Hi friends,

In this post, we will learn how to PHP Ajax GET Request Example. i explained simply step by step jQuery AJAX GET Methods example with PHP. Here you will learn jQuery Ajax GET Request method with PHP. This tutorial will give you simple example of How to send GET AJAX request with JavaScript.

I will give you simple Example of how to Ajax GET request with jQuery and PHP.

So let's see bellow example:

index.php


<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="utf-8">

<title>How to use Get Request with Ajax in PHP</title>

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">

<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>

<style type="text/css">

</style>

</head>

<body>

<div class="container" style="margin-top: 150px;">

<h1 class="text-center">How to use Get Request with Ajax in PHP</h1>

<div class="card mt-5">

<div class="card-header">

<h3 class="text-center">Content of The Result Will be Replaced by The Server Date and Time</h3>

</div>

<div class="card-body">

<div id="result"></div>

</div>

<div class="card-footer text-end">

<button type="button" class="btn btn-primary">Date and Time</button>

</div>

<div class="stap"></div>

</div>

</div>

</body>

<script>

$(document).ready(function(){

$("button").click(function(){

$.get("date-time.php", function(data){

$("#result").html(data);

});

});

});

</script>

</html>

date-time.php

<?php

echo date("F d, Y h:i:s A");

?>

Output:

I hope it will help you....

#PHP