Fork me on GitHub

jQuery xRequest Simple plugin to Ajax Request

Javascript

                        $(function() {
                            // Initialize
                            var myrequest = new xRequest({
                                url: 'server.php',
                                onStart: function() {
                                    $('#console').text('Sending..');
                                },
                                onSuccess: function(json) {
                                    if (json) {
                                        $('#console').html(json.time + '\n' + json.hash);
                                    }
                                }
                            });

                            $('#mybutton').on('click', function() {

                                // Checks if plugin is sending.
                                if (!myrequest.isSending()) {
                                    // Set one param on the fly
                                    myrequest.setData('myparam', 0);

                                    // Send request
                                    myrequest.send();
                                }

                            });
                        });
                    

PHP

                        <?php
                            
                            // JSON output
                            echo json_encode(array(
                                'time' => '<b>Server time:</b> ' . time(),
                                'hash' => '<b>Server hash (md5):</b> ' . hash('md5', time())
                            ));
                    

Live


Please press the button !