ajax example

by Brent Coder

HTML

<script src="https://code.jquery.com/jquery-1.5.2.js"></script>
<textarea id="log"></textarea>
<input type="button" id="button" value="Click Me">

CSS

#log{
    width: 500px;
    height:200px;
}

JavaScript

var i = 0;

function log(s) {
    $('#log').val($('#log').val() + '\n' + (++i) + ': ' + s);
}
var data = "Hello";
log('before ajax call');

//setup the event handler for the button
$('#button').click(function() {
//disable the button for now (this will be enabled when the data is received)
$('#button').attr('disabled', true);

    $.ajax({
    url: 'test',
    success: function(data) {
        log('in success callback');
        log('received data: ' + data);
        //enable the button
        $('#button').attr('disabled', false);
    }
});

});





log('after ajax call');

$(document).ready(function() {
    log('document ready');
    setTimeout(function() {
        log('timeout');
    }, 10000);
});