couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject jquery-couch commit: updated refs/heads/master to 9806ac9
Date Wed, 01 Jun 2016 20:21:04 GMT
Repository: couchdb-jquery-couch
Updated Branches:
  refs/heads/master 102e663aa -> 9806ac965


Fix HTTP Accept header for list query

Given following list function
```
function(head, req) {
  provides('text', function(){
    start({
      'headers': {
        'Content-Type': 'text/plain'
      }
    });
    send('Hello list!');
  });
}
```

It will get HTTP 406 error, because the default
Accept header is set to `application/json`.

See Also: couchapp/couchapp#234


Project: http://git-wip-us.apache.org/repos/asf/couchdb-jquery-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-jquery-couch/commit/9806ac96
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-jquery-couch/tree/9806ac96
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-jquery-couch/diff/9806ac96

Branch: refs/heads/master
Commit: 9806ac965cb03fce90423bad3d5f771a40ac9fc1
Parents: 102e663
Author: Iblis Lin <iblis@hs.ntnu.edu.tw>
Authored: Thu May 12 20:31:10 2016 +0800
Committer: Iblis Lin <iblis@hs.ntnu.edu.tw>
Committed: Thu May 12 20:31:10 2016 +0800

----------------------------------------------------------------------
 jquery.couch.js | 37 ++++++++++++++++++++++++++-----------
 1 file changed, 26 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-jquery-couch/blob/9806ac96/jquery.couch.js
----------------------------------------------------------------------
diff --git a/jquery.couch.js b/jquery.couch.js
index 561d6f4..b9b9a56 100644
--- a/jquery.couch.js
+++ b/jquery.couch.js
@@ -838,7 +838,11 @@
               url: this.uri + '_design/' + list[0] +
                    '/_list/' + list[1] + '/' + view + encodeOptions(options)
               },
-              ajaxOptions, 'An error occurred accessing the list'
+              ajaxOptions,
+              'An error occurred accessing the list',
+              {
+                headers: {'Accept': '*/*'},
+              }
           );
         },
 
@@ -1009,16 +1013,27 @@
       },
       complete: function(req) {
         var reqDuration = (new Date()).getTime() - timeStart;
-        try {
-          var resp = $.parseJSON(req.responseText);
-        } catch(e) {
-          if (options.error) {
-            options.error(req.status, req, e);
-          } else {
-            throw errorMessage + ': ' + e;
+
+        if (req.getResponseHeader('Content-Type') === 'application/json') {
+          try {
+            var resp = $.parseJSON(req.responseText);
+          } catch(e) {
+            if (options.error) {
+              options.error(req.status, req, e);
+            } else {
+              throw errorMessage + ': ' + e;
+            }
+            return;
           }
-          return;
         }
+        else {
+          /**
+           * i.e. In the case of the response of a list function,
+           * the content type can be various
+           */
+          var resp = req.responseText;
+        }
+
         if (options.ajaxStart) {
           options.ajaxStart(resp);
         }
@@ -1026,8 +1041,8 @@
           if (options.beforeSuccess) options.beforeSuccess(req, resp, reqDuration);
           if (options.success) options.success(resp, reqDuration);
         } else if (options.error) {
-          options.error(req.status, resp && resp.error ||
-                        errorMessage, resp && resp.reason || "no response",
+          options.error(req.status, resp && resp.error || errorMessage,
+                        resp && resp.reason || resp || "no response",
                         reqDuration);
         } else {
           throw errorMessage + ": " + resp.reason;


Mime
View raw message