我正在尝试发布输入框的值和已检查单选按钮的获取值,并根据选中的单选按钮执行查询...但我的成功函数未执行...
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);
答案 0 :(得分:1)
当我遇到这些类型的问题时,我将添加一个错误函数并将详细信息输出到控制台日志,以便它可以帮助找出错误。像这样:
,success: function(data){
alert("success");
},error: function(e){
console.log(e);
}
答案 1 :(得分:0)
试试这个
var callback = function( resp ) {
alert(123);
}
$.post(url, data, callback, "json");
答案 2 :(得分:0)
<input type="text" name="input"> </input>
错了,你错过了我相信的ID:
<input type="text" name="input" id="input" />
您还需要检查脚本是否正在执行。如果您的JavaScript中没有返回任何内容,则意味着脚本在服务器端失败。