我将按钮组织成按钮组,我希望通过php从此按钮组中获取所选值 我使用ajax将值从form.php发送到value.php 这是按钮组的代码
<div class="btn-group btn-toggle" name="btn-group" id="btn-group">
<button class="btn btn-lg btn-Primary<?php if($row['self_reg']=="ON") echo " active"?>" value="ON">ON</button>
<button class="btn btn-lg btn-default <?php if($row['self_reg']=="OFF") echo "active"?>" value="OFF">OFF</button>
</div>
这是ajax代码
<script type="text/javascript">
$(document).ready(function (e) {
$("#uploadimage").on('submit', (function (e) {
e.preventDefault();
$.ajax({
url: "Save.php?id=self_register", // Url to which the request is send
type: "POST", // Type of request to be send, called as method
data: new FormData(this), // Data sent to server, a set of key/value pairs (i.e. form fields and values)
contentType: false, // The content type used when sending data to the server.
cache: false, // To unable request pages to be cached
processData:false, // To send DOMDocument or non processed data file it is set to false
success: function (data) // A function to be called if request succeeds
{
//$('#loading').hide();
$("#result").html(data);
}
});
}));
});
</script>
我使用php代码从ajax获取值
$button-group=$_POST['btn-group']
但不幸的是,它没有用
答案 0 :(得分:0)
这是最简单的方法:
页:
<form action="sohandler.php" method="post">
<input type="submit" class="btn btn-lg btn-Primary<?php if($row[ 'self_reg' ]=='ON') echo " active ";?>" name="btn" value="ON"></input>
<input type="submit" class="btn btn-lg btn-default <?php if($row[ 'self_reg' ]=='OFF') echo " active ";?>" name="btn" value="OFF"></input>
</form>
处理程序:
<?php
$btn = $_POST[ 'btn' ]; /* Note that you can NOT use "-" in variables */
echo $btn;
?>