我有一个代码,其中我想通过ajax调用将检查的checkbpxes值发送到下一个php页面。但是我无法正确发送它。以前我曾经问过类似的问题。
以下是代码
<html>
<head>
<title>Insert title here</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
function get_check_value() {
var c_value = [];
$('input[name="services"]:checked').each(function () {
c_value.push(this.value);
});
//return c_value.join(',');
}
$(document).ready(function(){
$('#btnSubmit').on('click', function () {
alert("hi");
//var os = $('#originState').val();
//var c = $('#commodity').val();
//var ds = $('#destState').val();
var ser = get_check_value();
//var queryString = "os=" + os;
var queryString = "&ser=" + ser;
$.ajax({
type: "GET",
url:'sortingajax.php',
data:"queryString="+querystring,
success:function(data){
alert(data);
console.log(data);
$('#results').html(data);
}
});
});
});
</script>
<form name="searchForm">
<input type="checkbox" name="services" value="twic" />TWIC
<br/>
<input type="checkbox" name="services" value="enclosedTrucking" />Enclosed Trucking
<br/>
<input type="checkbox" name="services" value="flatBedTrucking" />Flat Bed Trucking
<br/>
<input type="submit" id="btnSubmit" value="Submit" />
</form>
<div id="results">
</div>
</body>
</html>
ajaxcall.php
<?php
include('connection.php');
$query=$_GET['querystring'];
echo $query;
$countsql='SELECT * FROM table1 ';
$countsql1=mysql_query($countsql);
$numrows = mysql_num_rows($countsql1);
$countArray2=array();
while($row = mysql_fetch_array($countsql1)) {
// Append to the array
$Array2[] = $row;
}
?>
<?php
foreach($Array2 as $array)
{
?>
<div class="search">hi</div>
<?php
$i++;
}
?>
我现在无法使用ajaxcall html内容获取内容。但我无法做到这一点.. 请指导我guyzzz
答案 0 :(得分:0)
如果我正确理解了您要实现的目标,可以在表单中添加隐藏的输入并传递值,您的脚本会将其设置为隐藏控件。
<form name="searchForm">
<input type="hidden" id="checkboxCollection">
<input type="checkbox" name="services" value="twic" />TWIC
<br/>
<input type="checkbox" name="services" value="enclosedTrucking" />Enclosed Trucking
<br/>
<input type="checkbox" name="services" value="flatBedTrucking" />Flat Bed Trucking
<br/>
<input type="submit" id="btnSubmit" value="Submit" />
</form>
然后脚本将变为
function get_check_value() {
var c_value = [];
$('input[name="services"]:checked').each(function () {
c_value.push(this.value);
});
$('#checkboxCollection').val(c_value.join(','));
//return c_value.join(',');
}
然后在提交表单时阅读checkboxCollection。