AJAX With JQuery
AJAX With JQuery
http://www.jquery.com/
jQuery is a JavaScript library based around the idea of
attaching functionality to selected groups of elements.
The main function in jQuery is the selector, $, which
works like:
$("#thisisanid") -- finds the element with that id
$("div") -- finds all divs
Many more syntaxes are supported.
Once a group of elements (or a single element) has
been selected, you can call jQuery functions that act on
the entire group.
It also has some very easy-to-use AJAX wrappers.
More on jQuery
$("somelink").ready(function() { // EVENT
$("somelink").fadeOut(); // ACTION
});
A simple example of jQuery
<body>
<div id="thediv" style="display:none;">
Content not yet loaded.
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#thediv").fadeIn();
});
</script>
</body>
Adding AJAX
$.get('data.html', function(response) {
alert("Data incoming...");
$("#thediv").html(response);
});
Even simpler
?>
Adding an event to the text field
$.get( 'username_check.php',
{ username: $("#username").val() },
function(response) {
if (response == "TAKEN") {
$('#username_error_box').html("This username is taken.");
}
});
Security concerns