我正在尝试发布输入框的值和选中的单选按钮的获取值,并根据选中的单选按钮执行查询......但我的成功功能没有执行......
html格式:
<form class="form-inline" id="myForm">
<label class="radio">
<input type="radio" id="title1" name="title" value="title">
Title
</label>
<label class="radio">
<input type="radio" id="author" name="title" value="author">
Author
</label>
<label class="radio">
<input type="radio" id="subject" name="title" value="subject">
Subject
</label><br>
<input type="text" name="input"> </input>
<button class="btn btn-inverse" id="download" >Go</button>
</form>
jQuery :
$('document').ready(function(){
$('input[name=title]:first').attr('checked', true);
$('#download').click(function(){
value = $('input[name=title]:checked', '#myForm').val();
alert(value);
var input = $('#input').attr('value');
dataString = 'title='+ value +'&input='+input;
wurl = "downloadE.php";
$.ajax({url: wurl, type: "POST",dataType: "json",data:dataString ,success: function(data){
alert("success");
}
})
})
});
php代码:
$value = $_POST['title'];
$output = $_POST['input'];
if($value=="title")
{
$query = " select * from library where Title = '$output'; ";
}
else if($value=="author")
{
$query = " select * from library where Author = '$output'; ";
}
else if($value=="subject")
{
$query = " select * from library where Subject = '$output'; ";
}
$result = mysql_query($query);
$ret = array();
while($info = mysql_fetch_array( $result )){
$ret[] = $info;
}
echo json_encode($ret);