カントはこれを理解しているようです。同じクラス名を持つすべての要素の値を取得するJavaScript関数があります。
var total = $(".bob").map(function() {
return $(this).val();
}).get();
var queryString = "?total="+total;
http.open("GET", "product.php" + queryString, true);
http.onreadystatechange = rgetHttpRes;
http.send(null);
配列をphpファイルに渡します-
if (isset($_GET['total'])) {
$price = $_GET['total'];
$num = array($price);
$result = array_sum($num);
echo($result);
}
// So I passed 2 integers with the JavaScript function: 15.99 and 10.99 into this php function.
It will only return one of them: 10.99 //
私がこれをするとき:
if (isset($_GET['total'])) {
$price = $_GET['total'];
$num = array($price);
print_r($num);
}
これは私が得る出力です:
Array ( [0] => 15.99, 10.99 )
なぜそれがそれらを印刷しないのか理解できません
Array ( [0] => 15.99 [1] => 10.99 )
誰かアイデアはありますか?