jquery 함수에서 php 함수를 호출하여 일부 값을 계산하고 세션에 값을 저장하고 세션에 저장된 값을 나열하려고합니다. 마우스 클릭 이벤트에서 HTML 폼의 jquery 함수에 값을 전달합니다. 그리고 나는 이것을 달성하기 위해 휴경 코드를 사용하고 있습니다. jquery 함수에서 PHP 함수를 호출하는 방법
이
하나의 PHP 파일 이름 totalprice.php에서 HTML 양식 코드 :<table width="100%" >
<tr>
<td >type</td>
<td><select name="costtype" id="costype">
<option>one time</option>\n<option>multi</option>\n
</select></td></tr>
<tr>
<td align="right">destination </td>
<td> <select name="destination" id ="destination"><option>Lagos</option>\n<option>Oyo</option>\n<option>Kano</option>\n<option>Rivers</option>\n<option>Edo</option>\n<option>Ogun</option>\n<option>Kaduna</option>\n<option>Plateau</option>\n<option>Anambra</option>\n<option>Delta</option></select></td>
</tr>
<tr>
<td align="right">Total eight (Kg) </td>
<td><input type="text" size="10" name="weight" id="weight"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Submit" onclick="javascript:calculate()" name="caliculate" class="button"></td>
</tr>
</tbody></table>
<div id="testtable">cal value will be displayed here.</div>
</form>
그리고 이것은 JQuery와 기능
function calculate() {
var costtype = $("#costype").val();
var destination = $("#destination").val();
var totalweight = $("#weight").val();
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==0)
{
document.getElementById("testtable").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST","caltest.php?item="+escape(costtype)+"&totalweight="+escape(totalweight)+"&destination"+escape(destination),true);
xmlhttp.send();
}
입니다 이것은 테이블
다음$itemtype = urldecode($_POST['item']);
$destination = urldecode($_POST['destination']);
$totalweight = urldecode($_POST['totalweight']);
$sql = "select price from prices_list where lower(costtype)='".strtolower($itemtype)."' ";
$price=0;
$Result = mysql_query($sql) ;
while ($row = mysql_fetch_array($Result))
{
$price = (isset($row['price'])) ? $row['price'] : "";
}
$price = round($price,2);
$costcharges = $price*$totalweight;
$costtcharges = round($costcharges,2);
내가
$ fee_details = $ test_fee 세션에 데이터를 저장하는 몇 가지 코드를하고 있어요을 사용하여 내가 세션 데이터를 계산을하고 표시하고있어 경우 파일 caltest.php -> storetestfee ($ itemtype, $ totalweight, $ destination, $ costcharges);
echo "<table width='75%' >
<tbody><tr>
<th width='2%' class='highlight'><b>#</b></th>
<th width='30%' class='highlight'><b>Item </b></th>
<th width='23%' class='highlight'><b>Destination</b></th>
<th width='5%' class='highlight'><b>weight (Kg) </b></th>
<th width='10%' class='highlight'><b>cost Charge</b></th>
</tr>";
if(count($fee_details)>0)
{$i=0;
foreach($fee_details as $key=>$test_price)
{$i++;
echo " <tr> ";
echo "<td>".$i."</td>";
echo "<td>".$test_price['item_type']."</td>";
echo "<td>".$test_price['destination']."</td>";
echo "<td>".$test_price['totalweight']."</td>";
echo "<td>".$courier_details['weightcharges']."</td>";
echo " </tr> ";
}}
echo "</tbody>
</table>";
이 코드는 jquery를 사용하여 직접 작업했을 때 완벽하게 작동합니다. 페이지를 새로 고치지 않고이 작업을 수행하기를 원합니다. 코드에서 실수를 저지르고있는 곳을 도와주세요. 제발. 고맙습니다.
SQL 인젝션 취약점이 있습니다. – SLaks
jQuery를 사용한다면'XMLHttpRequest'를 사용하는 것이 무엇이겠습니까?! – nickb
jQuery AJAX를 사용해야합니다. – SLaks