Skip to content

Commit

Permalink
Ajax: fix parsing response Content-Type from the server
Browse files Browse the repository at this point in the history
Fixes #699
  • Loading branch information
mislav committed Mar 3, 2013
1 parent 3771d17 commit 9b77aca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
}

function mimeToDataType(mime) {
if (mime) mime = mime.split(';', 2)[0]
return mime && ( mime == htmlType ? 'html' :
mime == jsonType ? 'json' :
scriptTypeRE.test(mime) ? 'script' :
Expand Down
13 changes: 13 additions & 0 deletions test/ajax.html
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,19 @@ <h1>Zepto Ajax unit tests</h1>
$.ajax({ url: 'echo' })
},

testAjaxJSON: function(t){
t.pause()
resumeOnAjaxError(t)

$.ajax({
url: 'json',
headers: { accept: 'application/json' },
success: t.reg.resumeHandler('success', function(data){
t.assertEqual('world', data.hello)
})
})
},

testAjaxGetJSON: function(t){
t.pause()
resumeOnAjaxError(t)
Expand Down

0 comments on commit 9b77aca

Please sign in to comment.