2016-09-26 7 views
-1

でJSONでのHTMLテキストの解析エラーが私のjsバイオリンと私はこれまでのところ、私はこれらの文字に私のjavascriptのファイルIにJavascriptがここでの位置の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()] 

            ]]; 

を脱出しようとしたPHPコードを脱出しようとしてテキストです含めないでください https://jsfiddle.net/tsjfkwto/

+0

関連:http://stackoverflow.com/questions/23740548/how-to-pass-variables-and-data-from-php-to-javascript/ –

答えて

1

を解析中

var productConfig = '<?php echo json_encode($datas);?>'; 

だったので、これはPHPコードのみを記述キーでそのエラーがされています' S:(JSONはJavaScriptのリテラル構文のサブセットであるため)

var productConfig = <?php echo json_encode($datas);?>; 
// No ' here -------^--------------------------------^ 

json_encodeが割り当ての右側の有効なJavaScriptの値を出力します。単純な文字列をエンコードする場合は、適切な引用符を使用します。オブジェクト構造をエンコーディングしている場合は、正しいオブジェクト構造(引用符で囲まれていないはずです)を持ちます。

関連する問題