Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Sven Franck
jio
Commits
6b246fa8
Commit
6b246fa8
authored
Aug 29, 2013
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jIO.util.ajax added
parent
28e451c7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
1 deletion
+26
-1
src/jio/core/util.js
src/jio/core/util.js
+26
-1
No files found.
src/jio/core/util.js
View file @
6b246fa8
/*jslint indent: 2, maxlen: 80, nomen: true, sloppy: true */
/*global exports, Blob, FileReader, Deferred, hex_sha256 */
/*global exports, Blob, FileReader, Deferred, hex_sha256
, XMLHttpRequest
*/
/**
* Do not exports these tools unless they are not writable, not configurable.
...
...
@@ -318,6 +318,31 @@ function readBlobAsBinaryString(blob) {
}
exports
.
util
.
readBlobAsBinaryString
=
readBlobAsBinaryString
;
/**
* Send request with XHR and return a promise.
*
* @param {String} method The request method
* @param {String} url The url
* @param {Any} [data] The data to send
* @param {Function} [before_send] A function called just before send request.
* The first parameter of this function is the XHR object.
* @return {Promise} The promise
*/
function
ajax
(
method
,
url
,
data
,
before_send
)
{
var
xhr
=
new
XMLHttpRequest
(),
deferred
=
new
Deferred
();
xhr
.
open
(
method
,
url
,
true
);
xhr
.
responseType
=
"
blob
"
;
xhr
.
onload
=
deferred
.
resolve
.
bind
(
deferred
);
xhr
.
onerror
=
deferred
.
reject
.
bind
(
deferred
);
xhr
.
onprogress
=
deferred
.
notify
.
bind
(
deferred
);
if
(
typeof
before_send
===
'
function
'
)
{
before_send
(
xhr
);
}
xhr
.
send
(
data
);
return
deferred
.
promise
();
}
exports
.
util
.
ajax
=
ajax
;
/**
* Acts like `Array.prototype.concat` but does not create a copy of the original
* array. It extends the original array and return it.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment