我想在JSON中使用JS变量。
var add = mixItems[i][0] + "," + mixItems[i][1];
jQuery.getJSON("wp-content/plugins/proteinmixer/php/addtocart.php" , function(data){
});
PHP:
require_once('../../../../wp-blog-header.php');
header('Content-Type:application/json');
global $woocommerce;
$productId = 66;
$quantity = 10;
//$add = $productId.",".$quantity."";
//$add = add;
$addtocart = $woocommerce->cart->add_to_cart($add);
echo json_encode($addtocart);
我需要JSON中的变量ADD。
答案 0 :(得分:1)
您可以使用JSON.stringify():
将任何Javascript值/对象转换为JSON字符串var add = mixItems[i][0] + "," + mixItems[i][1];
var jsonAdd = JSON.stringify(add);