Index: src/wp-admin/includes/ajax-actions.php
===================================================================
--- src/wp-admin/includes/ajax-actions.php	(revision 31373)
+++ src/wp-admin/includes/ajax-actions.php	(working copy)
@@ -1838,79 +1838,79 @@
 	$wp_customize->widgets->wp_ajax_update_widget();
 }
 
 /**
  * Ajax handler for uploading attachments
  *
  * @since 3.3.0
  */
 function wp_ajax_upload_attachment() {
 	check_ajax_referer( 'media-form' );
 
 	if ( ! current_user_can( 'upload_files' ) ) {
 		wp_send_json_error( array(
 			'message'  => __( "You don't have permission to upload files." ),
 			'filename' => $_FILES['async-upload']['name'],
-		) );
+		), 'text/html' );
 	}
 
 	if ( isset( $_REQUEST['post_id'] ) ) {
 		$post_id = $_REQUEST['post_id'];
 		if ( ! current_user_can( 'edit_post', $post_id ) ) {
 			wp_send_json_error( array(
 				'message'  => __( "You don't have permission to attach files to this post." ),
 				'filename' => $_FILES['async-upload']['name'],
-			) );
+			), 'text/html' );
 		}
 	} else {
 		$post_id = null;
 	}
 
 	$post_data = isset( $_REQUEST['post_data'] ) ? $_REQUEST['post_data'] : array();
 
 	// If the context is custom header or background, make sure the uploaded file is an image.
 	if ( isset( $post_data['context'] ) && in_array( $post_data['context'], array( 'custom-header', 'custom-background' ) ) ) {
 		$wp_filetype = wp_check_filetype_and_ext( $_FILES['async-upload']['tmp_name'], $_FILES['async-upload']['name'] );
 		if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) {
 			wp_send_json_error( array(
 				'message'  => __( 'The uploaded file is not a valid image. Please try again.' ),
 				'filename' => $_FILES['async-upload']['name'],
-			) );
+			), 'text/html' );
 		}
 	}
 
 	$attachment_id = media_handle_upload( 'async-upload', $post_id, $post_data );
 
 	if ( is_wp_error( $attachment_id ) ) {
 		wp_send_json_error( array(
 			'message'  => $attachment_id->get_error_message(),
 			'filename' => $_FILES['async-upload']['name'],
-		) );
+		), 'text/html' );
 	}
 
 	if ( isset( $post_data['context'] ) && isset( $post_data['theme'] ) ) {
 		if ( 'custom-background' === $post_data['context'] )
 			update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', $post_data['theme'] );
 
 		if ( 'custom-header' === $post_data['context'] )
 			update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', $post_data['theme'] );
 	}
 
 	if ( ! $attachment = wp_prepare_attachment_for_js( $attachment_id ) )
 		wp_die();
 
-	wp_send_json_success( $attachment );
+	wp_send_json_success( $attachment, 'text/html' );
 }
 
 /**
  * Ajax handler for image editing.
  *
  * @since 3.1.0
  */
 function wp_ajax_image_editor() {
 	$attachment_id = intval($_POST['postid']);
 	if ( empty($attachment_id) || !current_user_can('edit_post', $attachment_id) )
 		wp_die( -1 );
 
 	check_ajax_referer( "image_editor-$attachment_id" );
 	include_once( ABSPATH . 'wp-admin/includes/image-edit.php' );
 
Index: src/wp-includes/functions.php
===================================================================
--- src/wp-includes/functions.php	(revision 31373)
+++ src/wp-includes/functions.php	(working copy)
@@ -2769,89 +2769,97 @@
 		} else {
 			return mb_convert_encoding( $string, 'UTF-8', 'UTF-8' );
 		}
 	} else {
 		return wp_check_invalid_utf8( $string, true );
 	}
 }
 
 /**
  * Send a JSON response back to an Ajax request.
  *
  * @since 3.5.0
  *
  * @param mixed $response Variable (usually an array or object) to encode as JSON,
  *                        then print and die.
+ * @param string $content_type Content-Type to return the JSON as.
  */
-function wp_send_json( $response ) {
-	@header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
+function wp_send_json( $response, $content_type = null ) {
+	if ( ! $content_type ) {
+		$content_type = 'application/json';
+	}
+	@header( 'Content-Type: ' . $content_type . '; charset=' . get_option( 'blog_charset' ) );
+
 	echo wp_json_encode( $response );
+
 	if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
 		wp_die();
 	else
 		die;
 }
 
 /**
  * Send a JSON response back to an Ajax request, indicating success.
  *
  * @since 3.5.0
  *
  * @param mixed $data Data to encode as JSON, then print and die.
+ * @param string $content_type Content-Type to return the JSON as.
  */
-function wp_send_json_success( $data = null ) {
+function wp_send_json_success( $data = null, $content_type = null ) {
 	$response = array( 'success' => true );
 
 	if ( isset( $data ) )
 		$response['data'] = $data;
 
-	wp_send_json( $response );
+	wp_send_json( $response, $content_type );
 }
 
 /**
  * Send a JSON response back to an Ajax request, indicating failure.
  *
  * If the `$data` parameter is a {@see WP_Error} object, the errors
  * within the object are processed and output as an array of error
  * codes and corresponding messages. All other types are output
  * without further processing.
  *
  * @since 3.5.0
  * @since 4.1.0 The `$data` parameter is now processed if a {@see WP_Error}
  *              object is passed in.
  *
  * @param mixed $data Data to encode as JSON, then print and die.
+ * @param string $content_type Content-Type to return the JSON as.
  */
-function wp_send_json_error( $data = null ) {
+function wp_send_json_error( $data = null, $content_type = null ) {
 	$response = array( 'success' => false );
 
 	if ( isset( $data ) ) {
 		if ( is_wp_error( $data ) ) {
 			$result = array();
 			foreach ( $data->errors as $code => $messages ) {
 				foreach ( $messages as $message ) {
 					$result[] = array( 'code' => $code, 'message' => $message );
 				}
 			}
 
 			$response['data'] = $result;
 		} else {
 			$response['data'] = $data;
 		}
 	}
 
-	wp_send_json( $response );
+	wp_send_json( $response, $content_type );
 }
 
 /**
  * Retrieve the WordPress home page URL.
  *
  * If the constant named 'WP_HOME' exists, then it will be used and returned
  * by the function. This can be used to counter the redirection on your local
  * development environment.
  *
  * @since 2.2.0
  * @access private
  *
  * @see WP_HOME
  *
  * @param string $url URL for the home location.
