Sha256: 2576bb2e59664781b1a9eed5944ca280085b5aee67f8cb93d939a6f14fdd501d

Contents?: true

Size: 717 Bytes

Versions: 7

Compression:

Stored size: 717 Bytes

Contents

/*
---

name: Request.Auto

description: Accepts both json and html as response

license: MIT-style license.

requires: 
  - Core/Request.JSON
  - Core/Request.HTML

provides: 
  - Request.Auto
...
*/

Request.Auto = new Class({
	Extends: Request,
	
	options: {
	  headers: {
			Accept: 'application/json, text/html'
		}
	},
	
	success: function() {
	  var contentType = this.getContentType();
	  if (!contentType) return false;
	  var type = contentType.indexOf('json') > -1 ? 'JSON' : false;
	  return (type ? Request[type] : Request).prototype.success.apply(this, arguments);
	},
	
	getContentType: function() {
	  return this.getHeader('Content-Type') ? this.getHeader('Content-Type').split(';')[0] : null;
	}
});

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
lsd_rails-0.1.6 Packages/mootools-ext/Source/Request/Request.Auto.js
lsd_rails-0.1.5 Packages/mootools-ext/Source/Request/Request.Auto.js
lsd_rails-0.1.4 Packages/mootools-ext/Source/Request/Request.Auto.js
lsd_rails-0.1.3 Packages/mootools-ext/Source/Request/Request.Auto.js
lsd_rails-0.1.2 Packages/mootools-ext/Source/Request/Request.Auto.js
lsd_rails-0.1.1 Packages/mootools-ext/Source/Request/Request.Auto.js
lsd_rails-0.1 Packages/mootools-ext/Source/Request/Request.Auto.js