-1
這是我的js小提琴,我一直在努力,到目前爲止逃脫PHP代碼的文字我試圖逃跑,這些字符JavaScript腳本的HTML文本錯誤的JSON的位置x的
$datas[] = ['attributes' => [$colorId => ['id' => $child->getColor(),
'name' => $product->getName(),
'productId' => $product->getId(),
'price' => number_format($product->getSpecialPrice(),2),
'rrp' => number_format($product->getMsrp(), 2),
'was' => number_format($product->getPrice(), 2),
'image' => Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $child->getImage(),
'size' => $child->getSize(),
'description' =>Mage::helper('core')->quoteEscape(htmlspecialchars(json_encode($product->getDescription()), ENT_COMPAT, 'UTF-8', false)),
// Mage::helper('core')->quoteEscape($product->getDescription()),
'promo' => Mage::helper('core')->quoteEscape($product->getProductpromobox()),
'sku' => $product->getSku(),
'netsuite' => $product->getInternalId()
],
$sizeId => ['id' => $child->getSize(),
'name' => $product->getName(),
'productId' => $product->getId(),
'price' => number_format($product->getSpecialPrice(),2),
'rrp' => number_format($product->getMsrp(), 2),
'was' => number_format($product->getPrice(), 2),
'image' => Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $child->getImage(),
'color' => $child->getColor(),
'description' => Mage::helper('core')->quoteEscape(json_encode(utf8_encode($product->getDescription()), ENT_COMPAT, 'UTF-8', false)),
// Mage::helper('core')->quoteEscape($product->getDescription()),
'promo' => Mage::helper('core')->quoteEscape($product->getProductpromobox()),
'sku' => $product->getSku(),
'netsuite' => $product->getInternalId()]
]];
在我的javascript文件我也就是
var productConfig = '<?php echo json_encode($datas);?>';
所以這是PHP代碼,以便誤差僅在描述鍵的同時解析 https://jsfiddle.net/tsjfkwto/
相關:http://stackoverflow.com/questions/23740548/how-to-pass-variables-and-data-from-php-to-javascript/ –