-2
我有這段代碼,但無法刷新頁面時無法更改提交的變量。你能幫我用AJAX做到嗎?使用AJAX選擇值提交PHP
代碼: ............................................ .....................................
<form name="devices" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<select name="device" id="device">
<option value="i1">i1</option>
<option value="i2">i2</option>
</select>
</form>
<?php
$device = "";
if(isset($_POST['device'])) {
$device = $_POST['device'];
}
switch ($device) {
case 'i1':
$w = 50;
break;
case 'i2':
$w = 100;
break;
default:
$w = 50;
break;
}
?>
<div style="width: <?=$w?>px; height: 100px;background-color: black;"></div>
嘗試在另一個文件中分離您的php代碼,然後調用它ajax –