Page 1 of 1

How to implement Ajax call using jQuery

Posted: Fri Jul 15, 2011 11:02 pm
by Saman
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>