Alien-Web-HalBrowser
view release on metacpan or search on metacpan
share/js/hal/views/response_body.js view on Meta::CPAN
template: _.template($('#response-body-template').html()),
_bodyAsStringFromEvent: function(e) {
var output = 'n/a';
if(e.resource !== null) {
output = JSON.stringify(e.resource, null, HAL.jsonIndent);
} else {
// The Ajax request "failed", but there may still be an
// interesting response body (possibly JSON) to show.
var content_type = e.jqxhr.getResponseHeader('content-type');
var responseText = e.jqxhr.responseText;
if(content_type == null || content_type.indexOf('text/') == 0) {
output = responseText;
} else if(content_type.indexOf('json') != -1) {
// Looks like json... try to parse it.
try {
var obj = JSON.parse(responseText);
output = JSON.stringify(obj, null, HAL.jsonIndent);
} catch (err) {
// JSON parse failed. Just show the raw text.
share/vendor/js/jquery-1.10.2.js view on Meta::CPAN
// Caches the header
setRequestHeader: function( name, value ) {
var lname = name.toLowerCase();
if ( !state ) {
name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
requestHeaders[ name ] = value;
}
return this;
},
// Overrides response content-type header
overrideMimeType: function( type ) {
if ( !state ) {
s.mimeType = type;
}
return this;
},
// Status-dependent callbacks
statusCode: function( map ) {
var code;
share/vendor/js/jquery-1.10.2.js view on Meta::CPAN
url: url,
type: method,
dataType: type,
data: data,
success: callback
});
};
});
/* Handles responses to an ajax request:
* - finds the right dataType (mediates between content-type and expected dataType)
* - returns the corresponding response
*/
function ajaxHandleResponses( s, jqXHR, responses ) {
var firstDataType, ct, finalDataType, type,
contents = s.contents,
dataTypes = s.dataTypes;
// Remove auto dataType and get content-type in the process
while( dataTypes[ 0 ] === "*" ) {
dataTypes.shift();
if ( ct === undefined ) {
ct = s.mimeType || jqXHR.getResponseHeader("Content-Type");
}
}
// Check if we're dealing with a known content-type
if ( ct ) {
for ( type in contents ) {
if ( contents[ type ] && contents[ type ].test( ct ) ) {
dataTypes.unshift( type );
break;
}
}
}
// Check to see if we have a response for the expected dataType
( run in 1.722 second using v1.01-cache-2.11-cpan-524268b4103 )