我有網絡電子商務,它使用傳遞代理網站的API rajaongkir.com, 我想使用傳遞代理的價格是我的數據庫中的變量。從內部發送變量php內部
她是文件order.php
<script type="text/javascript" src="js/script.js"></script>
<form action="input.php?input=inputform" method="post">
<table class="zebra-table">
<thead>
<tr>
<th>Kurir</th>
<th>Servis</th>
<th>Deskripsi Servis</th>
<th>Lama Kirim (hari)</th>
<th>Total Biaya (Rp)</th>
<th>Opsi</th>
</tr>
</thead>
<tbody id="resultsbox"></tbody>
</table>
的script.js
function cekHarga(){
//var origin = $('#oricity').val();
var origin = 35;
var destination = $('#descity').val();
var weight = $('#berat').val();
var courier = $('#service').val();
$.ajax({
url:'process.php?act=cost',
data:{origin:origin,destination:destination,weight:weight,courier:courier},
success:function(response){
$('#resultsbox').html(response);
},
error:function(){
$('#resultsbox').html('ERROR');
}
});
}
process.php
if(isset($_GET['act'])):
switch ($_GET['act']) {
$cost = $IdmoreRO->hitungOngkir($origin,$destination,$weight,$courier);
//parse json
$costarray = json_decode($cost);
$results = $costarray->rajaongkir->results;
if(!empty($results)):
foreach($results as $r):
foreach($r->costs as $rc):
foreach($rc->cost as $rcc):
echo "<tr><td>$r->code</td><td>$rc->service</td><td>$rc->description</td><td>$rcc->etd</td><td>".number_format($rcc->value)."</td> <td></td></tr>";
$bayarr=$rcc->value;
endforeach;
endforeach;
endforeach;
endif;
}
endif;
我可以在形式訪問變量$ bayarr在order.php。
如何發送變量$ bayarr在process.php到order.php?
你的問題有些含糊。如果你想把這個變量「發送」到'order.php',那麼頭部重定向('header(「Location:order.php」);')就是你要找的東西。如果你想使用order.php中的函數,你可以使用類方法(定義,包括和啓動)。請更確切地說明你真正想要的東西。 – Jan
當我嘗試所有代碼粘貼在這裏,它說錯誤張貼。我在PHP編程中太小氣了。我會學到更多。 thx尋求建議 – Hafidh