Javascript 向ajax发送数据
使用ajax将数据从表单发布到php。当我们更改单选按钮时,数据未清除。请检查代码。Javascript 向ajax发送数据,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,使用ajax将数据从表单发布到php。当我们更改单选按钮时,数据未清除。请检查代码。 这是密码,请帮我。 这是我的朋友 <form name="theform" action="" method="post" id="paymentHistory"> <div class="co1">Type: <table width="240"> <tr> <td>
这是密码,请帮我。 这是我的朋友
<form name="theform" action="" method="post" id="paymentHistory">
<div class="co1">Type:
<table width="240">
<tr>
<td>
<input type="checkbox" name="Successfull" value='Successfull'>
</td>
<td>Successfull</td>
<td>
<input type="checkbox" name="Failure" value='Failure' />
</td>
<td>Failure</td>
</tr>
</table>
</div>
<div class="co">Data Range:
<table width="422">
<table>
<div>
<tr>
<td style="width: 8px;">
<input type="radio" name="Today" id="Today" value='Today'>
</td>
<td style="width: 80px;">
<label for="Today">Today</label>
</td>
<td style="width: 8px;">
<input type="radio" name="Today" id="Lastweek" value='Lastweek'>
</td>
<td style="width: 80px;">
<label for="Lastweek">Lastweek</label>
</td>
<td style="width: 8px;">
<input type="radio" name="Today" id="30days" value='30days'>
</td>
<td style="width: 80px;">
<label for="30days">30days</label>
</td>
</table>
</div>
</form>
类型:
成功的
失败
数据范围:
今天
上周
30天
这是剧本
<script type="text/javascript">
$(document).ready(function () {
$('#paymentHistory input:radio').click(function () {
if (this.checked) {
var opts = [];
opts.push($('#paymentHistory input:radio:checked').val());
$('#paymentHistory :checkbox').click(function () {
alert($('#paymentHistory input:radio:checked').val())
if (this.checked) {
opts.push(this.name);
} else {
if (!this.checked) {
alert(this.name);
opts.pop(this.name)
}
}
$.ajax({
type: "POST",
url: "tabletest/submit.php",
dataType: 'json',
cache: false,
data: {
filterOpts: opts
},
success: function (records) {
$('#phones tbody').html(makeTable(records));
}
});
function makeTable(data) {
var tbl_body = "";
$.each(data, function () {
var tbl_row = "";
$.each(this, function (k, v) {
tbl_row += "<td align='center'>" + v + "</td>";
})
tbl_body += "<tr>" + tbl_row + "</tr>";
})
return tbl_body;
}
});
}
});
});
</script>
$(文档).ready(函数(){
$('#paymentHistory input:radio')。单击(函数(){
如果(选中此项){
var opts=[];
opts.push($('#paymentHistory输入:radio:checked').val();
$(“#paymentHistory:复选框”)。单击(函数(){
警报($('#paymentHistory input:radio:checked').val()
如果(选中此项){
opts.push(这个名称);
}否则{
如果(!this.checked){
警报(此名称);
opts.pop(此.name)
}
}
$.ajax({
类型:“POST”,
url:“tabletest/submit.php”,
数据类型:“json”,
cache:false,
数据:{
过滤器选项:opts
},
成功:功能(记录){
$('#phones tbody').html(makeTable(records));
}
});
函数makeTable(数据){
var tbl_body=“”;
$。每个(数据、函数(){
var tbl_row=“”;
$。每个(此,函数(k,v){
tbl_行+=“+v+”;
})
tbl_正文+=“”+tbl_行+“”;
})
返回tbl_体;
}
});
}
});
});
这是我的php代码数据无法获取。请帮助我
<?php
$select = 'SELECT *';
$from = ' FROM payment_details';
$where = ' WHERE TRUE';
$nickname = $_SESSION['username'];
$opts = $_POST['filterOpts'];
$options = explode("&",$opts);
$Today = "";
$Lastweek = "";
$days = "";
$Successfull = "";
$Failure = "";
foreach($options as $key)
{
$key = explode("=",$key);
$type = $key[2];
if ("Today" == $type)
{
$Today= "Today";
}
if ("Lastweek" == $type)
{
$Lastweek = "Lastweek";
}
if ("30days" == $type)
{
$days = "30days";
}
if ("Successfull" == $type)
{
$Successfull = "Successfull";
}
if ("Failure" == $type)
{
$Failure = "Failure";
}
}
if( $Today == "Today" )
{
date_default_timezone_set('Asia/Kolkata');
$d = date('Y-m-d 00:00:00');
$where .= " AND tran_ini_date >= '$d' ";
}
if('Lastweek' == $Lastweek)
{
$d = date('Y-m-d 00:00:00', strtotime("-7 days") );
$where .= " AND tran_ini_date >= '$d' ";
}
if('30days' == $days)
{
$d = date('Y-m-d 00:00:00', strtotime("-30 days") );
$where .= " AND tran_ini_date >= '$d' ";
}
if("30days" == $days)
{
$d = date('Y-m-d 00:00:00', strtotime("30 days") );
$where .= " AND tran_ini_date <= '$d' ";
}
$check = 0;
if('Successfull' == $Successfull)
{
$check = 1;
$where .= " AND (status='success' ";
}
if('Failure' == $Failure)
{
if($check == 0)
$where .= " AND (status='pending') ";
else
$where .= " OR status='pending') ";
}
$sql = $select . $from . $where . " and nickname="."'".$nickname."'";
$conn = mysql_connect("localhost","root","********");
if (!$conn)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("**********",$conn);
$result = mysql_query($sql,$conn);
$data = array();
while ($row = mysql_fetch_assoc($result))
{
$data[] = $row;
}
$json = json_encode($data);
echo($json);
echo $sql;
?>
您的代码中有错误,使用:复选框单击内部:无线电单击事件的方法不正确。请参阅适用于您的已修改代码:
$(document).ready(function ()
{
makeTable = function(data)
{
var tbl_body = "";
$.each(data, function() {
var tbl_row = "";
$.each(this, function(k , v) {
tbl_row += "<td align='center'>"+v+"</td>";
})
tbl_body += "<tr>"+tbl_row+"</tr>";
})
return tbl_body;
};
var pushToServer = function(opts){
alert(opts);
$.ajax({
type: "POST",
url: "tabletest/submit.php",
dataType : 'json',
cache: false,
data: {filterOpts: opts},
success: function(records){
$('#phones tbody').html(makeTable(records));
}
});
};
$('#paymentHistory input:radio, #paymentHistory input:checkbox').click(function() {
pushToServer($('#paymentHistory').serialize());
});
});
$(文档).ready(函数()
{
makeTable=函数(数据)
{
var tbl_body=“”;
$.each(数据,函数(){
var tbl_row=“”;
$。每个(此,函数(k,v){
tbl_行+=“+v+”;
})
tbl_正文+=“”+tbl_行+“”;
})
返回tbl_体;
};
var pushToServer=函数(opts){
警报(opts);
$.ajax({
类型:“POST”,
url:“tabletest/submit.php”,
数据类型:“json”,
cache:false,
数据:{filterOpts:opts},
成功:功能(记录){
$('#phones tbody').html(makeTable(records));
}
});
};
$(“#paymentHistory输入:单选,#paymentHistory输入:复选框”)。单击(函数(){
pushToServer($(“#paymentHistory”).serialize();
});
});
您的JavaScript第10行和第16行似乎有语法错误??请更正错误solution@sriTwo更多第41行和第43行。请在这些行上加一个分号,然后尝试。。。我认为这不是语法错误的地方!你能创建一个小提琴并提供它吗?请检查php并解决我的问题。谢谢。请检查php并解决我的问题。谢谢。请帮助我@QQping