https://github.com/jpillora/jquery.rest/html
Summary
A jQuery plugin for easy consumption of RESTful APIsjquery
Downloads
File Size Reportgit
Original: 10314 bytes. Minified: 5920 bytes. Gzipped: 1376 bytes.Features
- Simple
- Uses jQuery Deferred for Asynchonous chaining
- Basic Auth Support
- Helpful Error Messages
- Memory Cache
- Cross-domain Requests with XDomain
First setup your page:github
<!-- jQuery --> <script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <!-- jQuery rest --> <script src="http://jpillora.com/jquery.rest/dist/1/jquery.rest.min.js"></script> <!-- WARNING: I advise not using this link, instead download and host this library on your own server as GitHub has download limits --> <script> // Examples go here... </script>
Hello jquery.restajax
var client = new $.RestClient('/rest/api/'); client.add('foo'); client.foo.read(); // GET /rest/api/foo/ client.foo.read(42); // GET /rest/api/foo/42/ client.foo.read('forty-two'); // GET /rest/api/foo/forty-two/
Retrieving Results (Uses jQuery's $.Deferred)api
var client = new $.RestClient('/rest/api/'); client.add('foo'); var request = client.foo.read(); // GET /rest/api/foo/ request.done(function (data, textStatus, xhrObject){ alert('I have data: ' + data); }); // OR simply: client.foo.read().done(function (data){ alert('I have data: ' + data); });
更多功能和例子見:dom
https://github.com/jpillora/jquery.rest/this