У меня проблема при использовании jQuery Post, PHP возвращает все HTML-страницы страницы только что созданному HTML, а не только HTML, который выводится PHP.PHP jQuery Post - возвращает слишком много HTML
В качестве примера говорят PHP выходы: '<div>Some Content</div>'
Тогда JQuery сообщение возвращает: '<html><head>...all the head content...</head><body>...other content...<div>Some Content</div>'
Вот JQuery (ссылка на полный код: http://pastebin.com/U7R8PqX1):
jQuery("form[ID^=product_form]").submit(function() {
var current_url = js_data.current_url;
form_values = jQuery(this).serialize();
jQuery.post(current_url+"?ajax=true", form_values, function(returned_data) {
jQuery('div.shopping-cart').html(returned_data);
}
});
return false;
});
И вот PHP (версия 5.3.6 - ссылка на полный код: http://pastebin.com/zjSUUbmL):
function output_cart()
{
ob_start();
echo $this->output_cart_html();
$output = ob_get_contents();
ob_end_clean();
echo $output;
exit();
}
function output_cart_html() {
if (!isset($_SESSION['cart_items']))
{
$output = '<div class="cart_content faded">BASKET - Empty</div>';
return $output;
} else {
$total_items = 0;
$total_items = 0;
$items_in_cart = $_SESSION['cart_items'];
// work out total price and total items
foreach ($items_in_cart as $item_in_cart) {
$total_items += $item_in_cart['quantity'];
$total_price += floatval($item_in_cart['updated_price']*$item_in_cart['quantity']);
}
$template_url = get_bloginfo('template_directory');
$output = '';
$output_price = $dp_shopping_cart_settings['dp_currency_symbol'].number_format($total_price,2);
if($total_items == 1){ $item_text = ' Item'; } else { $item_text = ' Items'; }
$output .= $total_items . $item_text;
$output .= ' <span class="bullet"></span> Total '.$output_price;
// empty cart btn
$output .= '<form action="" method="post" class="empty_cart">
<input type="hidden" name="ajax_action" value="empty_cart" />
<span class="emptycart"> <a href="'.htmlentities(add_query_arg("ajax_action", "empty_cart", remove_query_arg("ajax")), ENT_QUOTES).'"><img src="'.$template_url.'/images/empty.png" width="9" height="9" title="Empty Your Items" alt="Empty Your Items" />Empty Your Cart</a></span>
</form>';
// check out btn
$output .= ' <span class="bullet"></span> <span class="gocheckout">'.$this->output_checkout_link().' </span>';
return $output;
}
}
Выхода буферизация вы используете есть совершенно излишний. Кроме того, я вижу только два (предполагаемых) класса методов. Где остальная часть кода PHP? – Phil
Привет, Фил, спасибо, что посмотрели, вот полный JQuery: http://pastebin.com/U7R8PqX1 и полный PHP: http://pastebin.com/zjSUUbmL –