Jquery ajax request example

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Today now in this post i would like to show you an example of Ajax request in Jquery. If you are a very fresher in jquery and laravel and you have no idea on how to work with post ajax request then bellow example can be help you. Here i will give you the example of POST ajax request also with json, we can also easily modify this example. So we can also fire GET ajax request by using this example. Now in the bellow example is a pretty simple to understand about how to work $.ajax method.

so let’s see the bellow example and can try to understand.

Example:

<html lang="en">
<head>
	<title>JQuery Ajax Demo</title>
	<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
<body>
	<button class="ajax">Click Here</button>
    <script type="text/javascript">
    	$(".ajax").click(function(){
		  $.ajax({
                        url: "{{route('asset.ssm.requisition-supply_check') }}",
			dataType: "json",
			type: "POST",
			data: {"id":"10"},
			success: function (data) {
			  alert(data);
			},
			error: function() {
			  alert('Error.');
			}
		  });
    	});
    </script>
</body>
</html>

Read Also : How to convert Object into Array in PHP?

Thanks for read. I hope it help you. For more you can follow us on facebook.

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →