Permalink
Browse files

infers type based on Content-Type header.

closes #70
  • Loading branch information...
1 parent 3d8b07a commit 2b751d2e4bd3557707e6c01935bad8db1237e6d9 @ded committed Feb 24, 2014
Showing with 11 additions and 12 deletions.
  1. +2 −1 .gitignore
  2. +1 −1 src/copyright.js
  3. +8 −9 src/reqwest.js
  4. +0 −1 use-me.sublime-workspace
View
@@ -1 +1,2 @@
-node_modules
+node_modules
+*.sublime-workspace
View
@@ -1,5 +1,5 @@
/*!
* Reqwest! A general purpose XHR connection manager
- * license MIT (c) Dustin Diaz 2013
+ * license MIT (c) Dustin Diaz 2014
* https://github.com/ded/reqwest
*/
View
@@ -68,8 +68,7 @@
if (r._aborted) return error(r.request)
if (r.request && r.request[readyState] == 4) {
r.request.onreadystatechange = noop
- if (twoHundo.test(r.request.status))
- success(r.request)
+ if (twoHundo.test(r.request.status)) success(r.request)
else
error(r.request)
}
@@ -134,9 +133,6 @@
// need this for IE due to out-of-order onreadystatechange(), binding script
// execution to an event listener gives us control over when the script
// is executed. See http://jaubourg.net/2010/07/loading-script-as-onclick-handler-of.html
- //
- // if this hack is used in IE10 jsonp callback are never called
- script.event = 'onclick'
script.htmlFor = script.id = '_reqwest_' + reqId
}
@@ -223,9 +219,12 @@
init.apply(this, arguments)
}
- function setType(url) {
- var m = url.match(/\.(json|jsonp|html|xml)(\?|$)/)
- return m ? m[1] : 'js'
+ function setType(header) {
+ // json, javascript, text/plain, text/html, xml
+ if (header.match('json')) return 'json'
+ if (header.match('javascript')) return 'js'
+ if (header.match('text')) return 'html'
+ if (header.match('xml')) return 'xml'
}
function init(o, fn) {
@@ -247,7 +246,6 @@
this._responseArgs = {}
var self = this
- , type = o['type'] || setType(this.url)
fn = fn || function () {}
@@ -284,6 +282,7 @@
}
function success (resp) {
+ var type = o['type'] || setType(resp.getResponseHeader('Content-Type'))
resp = (type !== 'jsonp') ? self.request : resp
// use global data filter on response text
var filteredResponse = globalSetupOptions.dataFilter(resp.responseText, type)
View
@@ -1 +0,0 @@
-{}

0 comments on commit 2b751d2

Please sign in to comment.