Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio-main
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Hardik Juneja
jio-main
Commits
d2c5f881
Commit
d2c5f881
authored
Aug 31, 2013
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util.ajax updated to give jquery like object parameter
parent
08666f6d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
14 deletions
+31
-14
src/jio/core/util.js
src/jio/core/util.js
+31
-14
No files found.
src/jio/core/util.js
View file @
d2c5f881
...
...
@@ -319,26 +319,43 @@ function readBlobAsBinaryString(blob) {
exports
.
util
.
readBlobAsBinaryString
=
readBlobAsBinaryString
;
/**
* Send request with XHR and return a promise.
* Send request with XHR and return a promise. xhr.onload: The promise is
* resolve when the status code is lower than 400 with the xhr object as first
* parameter. xhr.onerror: reject with xhr object as first
* parameter. xhr.onprogress: notifies the xhr object.
*
* @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.
* @param {Object} param The parameters
* @param {String} [param.type="GET"] The request method
* @param {String} [param.dataType=""] The data type to retrieve
* @param {String} param.url The url
* @param {Any} [param.data] The data to send
* @param {Function} [param.beforeSend] 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
);
function
ajax
(
param
)
{
var
k
,
xhr
=
new
XMLHttpRequest
(),
deferred
=
new
Deferred
();
xhr
.
open
(
param
.
type
||
"
GET
"
,
param
.
url
,
true
);
xhr
.
responseType
=
param
.
dataType
||
""
;
if
(
typeof
param
.
headers
===
'
object
'
&&
param
.
headers
!==
null
)
{
for
(
k
in
param
.
headers
)
{
if
(
param
.
headers
.
hasOwnProperty
(
k
))
{
xhr
.
setRequestHeader
(
k
,
param
.
headers
[
k
]);
}
}
}
xhr
.
onload
=
function
(
e
)
{
if
(
e
.
target
.
status
>=
400
)
{
return
deferred
.
reject
(
e
);
}
deferred
.
resolve
(
e
);
};
xhr
.
onerror
=
deferred
.
reject
.
bind
(
deferred
);
xhr
.
onprogress
=
deferred
.
notify
.
bind
(
deferred
);
if
(
typeof
before_s
end
===
'
function
'
)
{
before_s
end
(
xhr
);
if
(
typeof
param
.
beforeS
end
===
'
function
'
)
{
param
.
beforeS
end
(
xhr
);
}
xhr
.
send
(
data
);
xhr
.
send
(
param
.
data
);
return
deferred
.
promise
();
}
exports
.
util
.
ajax
=
ajax
;
...
...
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