Originally Posted by
DrByte
You didn't show what data you're POSTing ... just the headers.
Maybe it's better if you post your complete HTML of the page, and all the jQuery code also being loaded in the page.
I was going to post the full HTML rendered from Chrome Inspector Tool but I didn't know how to control the size of the "[HTML]" Tag box and it was rather large as-is.
The contents of ajax_compare.php:
PHP Code:
<?php
/**
* ajax_compare.php
* ajax call to show products selected for comparison
*
* @package general
* @copyright Copyright 2003-2010 Zen Cart Development Team
* @copyright Portions Copyright 2003 osCommerce
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version $Id: ajax_compare.php 00001 2011-01-28 5:23:52MT brit (docreativedesign.com) $
*/
require('includes/application_top.php');
include(DIR_WS_LANGUAGES . $_SESSION['language'].'/'.FILENAME_DEFINE_COMPARE_LANGUAGE);
// get values
$action = $_POST['action'];
$selected = $_POST['compare_id'];
$compare_array = array();
$comp_images = '';
$compare_warning = '';
$comp_value_count = count($_SESSION['compare']);
// add new products selected
if ($action == 'add') {
if ($comp_value_count < COMPARE_VALUE_COUNT) {
$compare_array[] = $selected;
foreach ($_SESSION['compare'] as $c) {
if ($c != $selected) {
$compare_array[] = $c;
}
}
$_SESSION['compare'] = array_unique($compare_array);
} else {
$compare_warning = '<div id="compareWarning">' . COMPARE_WARNING_START . COMPARE_VALUE_COUNT . COMPARE_WARNING_END . '</div>';
}
}
// remove products
if ($action == 'remove') {
foreach ($_SESSION['compare'] as $rValue) {
if ($rValue != $selected) {
$removed_compare_array[] = $rValue;
}
$_SESSION['compare'] = array_unique($removed_compare_array);
}
}
// return new value for the session
foreach ($_SESSION['compare'] as $value) {
if (!empty($value)) {
$product_comp_image = $db->Execute(
"SELECT p.products_id, p.master_categories_id, pd.products_name, p.products_image
FROM " . TABLE_PRODUCTS . " p
LEFT JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd
ON pd.products_id=p.products_id
WHERE p.products_id='".$value."'"
);
$comp_images .= '<div class="compareAdded"><a href="' . zen_href_link(zen_get_info_page($product_comp_image->fields['products_id']), 'cPath=' . (zen_get_generated_category_path_rev($product_comp_image->fields['master_categories_id'])) . '&products_id=' . $product_comp_image->fields['products_id']) . '">' . zen_image(DIR_WS_IMAGES . $product_comp_image->fields['products_image'], $product_comp_image->fields['products_name'], '', '35', 'class="listingProductImage"') . '</a><div>'.'<a name="rmv'.$product_comp_image->fields['products_id'].'" onclick="javascript: compareNew('.$product_comp_image->fields['products_id'].', \'remove\')" alt="remove">'.COMPARE_REMOVE.'</a>'.'</div></div>';
}
}
// return HTML view of found products
if (!empty($comp_images)) {
echo '<div id="compareMainWrapper"><div class="compareAdded compareButton">'.'<a href="index.php?main_page=compare" alt="compare">'.'<span class="cssButton">'.COMPARE_BUTTON_DEFAULT.'</span></a></div>'.$comp_images.'</div>';
} else { echo '<script type="text/javascript">' , 'hideCompare();' , '</script>'; }
echo '<br class="clearBoth" />';
// send back warning if more than allowed is selected
echo $compare_warning;
require('includes/application_bottom.php');
?>
The jQuery containing the .load(ajax_compare.php...):
Code:
$(document).ready(function(){
$('#compareResult:not(:has(.compareAdded))').css("display", "none");
for (index = 0; index < data.length; index++) {
$("input[name='" + data[index] + "']").prop("checked",true);
}
});
function compareNew(obj, action) {
$('#compareResult').show();
if ( $("input[name='" + obj + "']").is(":checked") && $("a[name='rmv" + obj + "']").length ) {
if ( action == 'remove' ) {
$("input[name='" + obj + "']").prop("checked",false);
} else if ( action == 'add' ) { }
}
else if ( $("input[name='" + obj + "']").is(":checked") && $("a[name='rmv" + obj + "']").length === 0 ) { }
else {
action = 'remove';
}
$('#compareProducts').load('ajax_compare.php', {'compare_id': obj, 'action': action});
}
function hideCompare() {
$('#compareResult').hide();
}
Bookmarks