Skip to content

Commit

Permalink
Use correct Content-Type header for JSON output
Browse files Browse the repository at this point in the history
  • Loading branch information
GeertDD committed Jan 16, 2013
1 parent 44013d4 commit 5da944a
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions woocommerce-ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ function woocommerce_sidebar_login_ajax_process() {

check_ajax_referer( 'woocommerce-sidebar-login-action', 'security' );

header( 'Content-Type: application/json; charset=utf-8' );

// Get post data
$creds = array();
$creds['user_login'] = $_REQUEST['user_login'];
Expand Down Expand Up @@ -73,8 +75,6 @@ function woocommerce_sidebar_login_ajax_process() {
}
}

header( 'content-type: application/json; charset=utf-8' );

echo esc_js( $_GET['callback'] ) . '(' . json_encode( $result ) . ')';

die();
Expand Down Expand Up @@ -219,6 +219,8 @@ function woocommerce_ajax_add_to_cart() {

check_ajax_referer( 'add-to-cart', 'security' );

header( 'Content-Type: application/json; charset=utf-8' );

$product_id = (int) apply_filters('woocommerce_add_to_cart_product_id', $_POST['product_id']);

$passed_validation = apply_filters('woocommerce_add_to_cart_validation', true, $product_id, 1);
Expand Down Expand Up @@ -360,6 +362,8 @@ function woocommerce_add_new_attribute() {

check_ajax_referer( 'add-attribute', 'security' );

header( 'Content-Type: application/json; charset=utf-8' );

$taxonomy = esc_attr( $_POST['taxonomy'] );
$term = stripslashes( $_POST['term'] );

Expand Down Expand Up @@ -914,6 +918,8 @@ function woocommerce_get_customer_details() {

check_ajax_referer( 'get-customer-details', 'security' );

header( 'Content-Type: application/json; charset=utf-8' );

$user_id = (int) trim(stripslashes($_POST['user_id']));
$type_to_load = esc_attr(trim(stripslashes($_POST['type_to_load'])));

Expand All @@ -931,7 +937,7 @@ function woocommerce_get_customer_details() {
$type_to_load . '_phone' => get_user_meta( $user_id, $type_to_load . '_phone', true ),
);

echo json_encode($customer_data);
echo json_encode( $customer_data );

// Quit out
die();
Expand Down Expand Up @@ -1223,6 +1229,8 @@ function woocommerce_calc_line_taxes() {

check_ajax_referer( 'calc-totals', 'security' );

header( 'Content-Type: application/json; charset=utf-8' );

$tax = new WC_Tax();

$taxes = $tax_rows = $item_taxes = $shipping_taxes = array();
Expand Down Expand Up @@ -1538,6 +1546,8 @@ function woocommerce_json_search_products( $x = '', $post_types = array('product

check_ajax_referer( 'search-products', 'security' );

header( 'Content-Type: application/json; charset=utf-8' );

$term = (string) urldecode(stripslashes(strip_tags($_GET['term'])));

if (empty($term)) die();
Expand Down Expand Up @@ -1649,6 +1659,8 @@ function woocommerce_json_search_customers() {

check_ajax_referer( 'search-customers', 'security' );

header( 'Content-Type: application/json; charset=utf-8' );

$term = urldecode( stripslashes( strip_tags( $_GET['term'] ) ) );

if ( empty( $term ) )
Expand Down Expand Up @@ -1785,6 +1797,8 @@ function woocommerce_product_ordering() {
if ( ! $post = get_post( $_POST['id'] ) )
die(-1);

header( 'Content-Type: application/json; charset=utf-8' );

$previd = isset( $_POST['previd'] ) ? $_POST['previd'] : false;
$nextid = isset( $_POST['nextid'] ) ? $_POST['nextid'] : false;
$new_pos = array(); // store new positions for ajax
Expand Down

0 comments on commit 5da944a

Please sign in to comment.