mirror of
https://github.com/samsonjs/samhuri.net.git
synced 2026-03-25 09:05:47 +00:00
fix a typo in SJS.request, future proof the global
This commit is contained in:
parent
9608e8e2c6
commit
0ac7943b29
1 changed files with 10 additions and 5 deletions
|
|
@ -1,8 +1,8 @@
|
|||
;(function() {
|
||||
if (typeof SJS === 'undefined') SJS = {}
|
||||
if (typeof window.SJS === 'undefined') window.SJS = {}
|
||||
|
||||
// cors xhr request, quacks like mikeal's request module
|
||||
SJS.request = function(options, cb) {
|
||||
window.SJS.request = function(options, cb) {
|
||||
var url = options.uri
|
||||
, method = options.method || 'GET'
|
||||
, headers = options.headers || {}
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
// withCredentials => cors
|
||||
if ('withCredentials' in xhr) {
|
||||
xhr.open(method, url, true)
|
||||
} else if (typeof XDomainRequest === 'functon') {
|
||||
} else if (typeof XDomainRequest === 'function') {
|
||||
xhr = new XDomainRequest()
|
||||
xhr.open(method, url)
|
||||
} else {
|
||||
|
|
@ -23,8 +23,13 @@
|
|||
xhr.setRequestHeader(k, headers[k])
|
||||
}
|
||||
xhr.onload = function() {
|
||||
var response = xhr.responseText
|
||||
cb(null, xhr, response)
|
||||
if (xhr.status === 200) {
|
||||
cb(null, xhr, xhr.responseText)
|
||||
}
|
||||
else {
|
||||
console.log('xhr error ' + xhr.status + ': ' + xhr.responseText)
|
||||
cb(new Error('error: ' + xhr.status))
|
||||
}
|
||||
}
|
||||
xhr.send(body)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue