From 9b77aca0349903aecc820c028580428896df6832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Sat, 2 Mar 2013 21:15:00 -0500 Subject: [PATCH] Ajax: fix parsing response Content-Type from the server Fixes #699 --- src/ajax.js | 1 + test/ajax.html | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/ajax.js b/src/ajax.js index af0c98b1b..822be1aab 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -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' : diff --git a/test/ajax.html b/test/ajax.html index 9ea638863..9c540e17e 100644 --- a/test/ajax.html +++ b/test/ajax.html @@ -252,6 +252,19 @@

Zepto Ajax unit tests

$.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)