Simple Ajax Request Plugin With jQuery and PHP - xRequest
File Size: | 31.3 KB |
---|---|
Views Total: | 971 |
Last Update: | |
Publish Date: | |
Official Website: | Go to website |
License: | MIT |

xRequest is a simple plugin to Ajax Request using jQuery and PHP. Check the demo page for more information.
How to use it:
1. Include jQuery library and jQuery xRequest plugin on the page
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> <script src="jquery.xrequest.js"></script>
2. The 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(); } }); });
3. The PHP
<?php // JSON output echo json_encode(array( 'time' => '<b>Server time:</b> ' . time(), 'hash' => '<b>Server hash (md5):</b> ' . hash('md5', time()) ));
Change log:
v1.0.3 (2014-09-27)
- update.
This awesome jQuery plugin is developed by joseluisq. For more Advanced Usages, please check the demo page or visit the official website.