輕量級的 AJAX 客戶端:jsonpipe
jsonpipe 是一個輕量級的 AJAX 客戶端,用于處理壓縮(chunked)的 JSON 響應信息。
示例代碼:
var jsonpipe = require('jsonpipe');
/**
* @param {String} url A string containing the URL to which the request is sent.
* @param {Object} url A set of key/value pairs that configure the Ajax request.
* @return {XMLHttpRequest} The XMLHttpRequest object for this request.
* @method flow
*/
jsonpipe.flow('http://api.com/items?q=batman', {
"delimiter": "", // String. The delimiter separating valid JSON objects; default is "\n\n"
"success": function(data) {
// Do something with this JSON chunk
},
"error": function(errorMsg) {
// Something wrong happened, check the error message
},
"complete": function(statusText) {
// Called after success/error, with the XHR status text
},
"timeout": 3000, // Number. Set a timeout (in milliseconds) for the request
"method": "GET", // String. The type of request to make (e.g. "POST", "GET", "PUT"); default is "GET"
"headers": { // Object. An object of additional header key/value pairs to send along with request
"X-Requested-With": "XMLHttpRequest"
},
"data": "" // String. A serialized string to be sent in a POST/PUT request
}); 本文由用戶 byb1234 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!