How to implement Ajax call using jQuery

Web programming topics
Post Reply
User avatar
Saman
Lieutenant Colonel
Lieutenant Colonel
Posts: 828
Joined: Fri Jul 31, 2009 10:32 pm
Location: Mount Lavinia

How to implement Ajax call using jQuery

Post by Saman » Fri Jul 15, 2011 11:02 pm

This is the most simple way to implement an Ajax call using jQuery. Change formId and inputFieldId with the ID of the form and input field you have to submit:

Code: Select all

<script type="text/javascript">
$(document).ready(function(){
	$("form#formId").submit(function() {
		inputField = $('#inputFieldId').attr('value');
		$.ajax({
			type: "POST",
			url: "yourpage.php",
			cache: false,
			data: "inputField ="+ inputField,
			success: function(html){
				$("#ajax-results").html(html);
			}
		});
		return false;
	});
});
</script>
Post Reply

Return to “Web programming”