mirror of
https://github.com/samsonjs/samhuri.net.git
synced 2026-04-27 14:57:40 +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() {
|
;(function() {
|
||||||
if (typeof SJS === 'undefined') SJS = {}
|
if (typeof window.SJS === 'undefined') window.SJS = {}
|
||||||
|
|
||||||
// cors xhr request, quacks like mikeal's request module
|
// cors xhr request, quacks like mikeal's request module
|
||||||
SJS.request = function(options, cb) {
|
window.SJS.request = function(options, cb) {
|
||||||
var url = options.uri
|
var url = options.uri
|
||||||
, method = options.method || 'GET'
|
, method = options.method || 'GET'
|
||||||
, headers = options.headers || {}
|
, headers = options.headers || {}
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
// withCredentials => cors
|
// withCredentials => cors
|
||||||
if ('withCredentials' in xhr) {
|
if ('withCredentials' in xhr) {
|
||||||
xhr.open(method, url, true)
|
xhr.open(method, url, true)
|
||||||
} else if (typeof XDomainRequest === 'functon') {
|
} else if (typeof XDomainRequest === 'function') {
|
||||||
xhr = new XDomainRequest()
|
xhr = new XDomainRequest()
|
||||||
xhr.open(method, url)
|
xhr.open(method, url)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -23,8 +23,13 @@
|
||||||
xhr.setRequestHeader(k, headers[k])
|
xhr.setRequestHeader(k, headers[k])
|
||||||
}
|
}
|
||||||
xhr.onload = function() {
|
xhr.onload = function() {
|
||||||
var response = xhr.responseText
|
if (xhr.status === 200) {
|
||||||
cb(null, xhr, response)
|
cb(null, xhr, xhr.responseText)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log('xhr error ' + xhr.status + ': ' + xhr.responseText)
|
||||||
|
cb(new Error('error: ' + xhr.status))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
xhr.send(body)
|
xhr.send(body)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue