} else { // if not success, mark it as an error
error = error || statusText;
+
+ // Set responseText if needed
+ if ( response ) {
+ jXHR.responseText = response;
+ }
}
// Set data for the fake xhr object
status
);
- // Guess response if needed & update datatype accordingly
- if ( status >= 200 && status < 300 ) {
- response =
- determineDataType(
- s,
- xhr.getResponseHeader("content-type"),
- xhr.responseText,
- xhr.responseXML );
- }
+ // Guess response & update dataType accordingly
+ response =
+ determineDataType(
+ s,
+ xhr.getResponseHeader("content-type"),
+ xhr.responseText,
+ xhr.responseXML );
}
// Call complete
--- /dev/null
+<?php
+
+header("HTTP/1.0 400 Bad Request");
+
+echo "plain text message";
\ No newline at end of file
});
});
+test("jQuery.ajax() - responseText on error", function() {
+
+ expect( 1 );
+
+ stop();
+
+ jQuery.ajax({
+ url: url("data/errorWithText.php"),
+ error: function(xhr) {
+ strictEqual( xhr.responseText , "plain text message" , "Test jXHR.responseText is filled for HTTP errors" );
+ },
+ complete: function() {
+ start();
+ }
+ });
+});
+
test(".ajax() - headers" , function() {
expect( 2 );