Php 使用组合框刷新页面而不刷新
如何使用组合框更新.php页面而不进行刷新? 我有这样一段代码,它获取组合的值并将其步进到页面,但这样做会重新加载页面,从而丢失初始搜索,但我需要传递值以保持上一次调查 代码:Php 使用组合框刷新页面而不刷新,php,mysql,ajax,Php,Mysql,Ajax,如何使用组合框更新.php页面而不进行刷新? 我有这样一段代码,它获取组合的值并将其步进到页面,但这样做会重新加载页面,从而丢失初始搜索,但我需要传递值以保持上一次调查 代码: 大众化 A-Z Z-A 功能值选择(过滤器) { window.location.href=“produtos.php?filtro=“+filtro; } 我正在尝试这样做: <script type="text/javascript" language="javascript"> function
大众化
A-Z
Z-A
功能值选择(过滤器)
{
window.location.href=“produtos.php?filtro=“+filtro;
}
我正在尝试这样做:
<script type="text/javascript" language="javascript">
function pesquisa(filtro) {
var id = $("#filtro").val();
$.ajax({
type: "GET",
url: produtos.php,
data: (filtto : id),
dataType: "json",
success: function(obj) {
$('#message')[0].value = filtro
}
}
});
}
</script>
函数pesquisa(filtro){
var id=$(“#filtro”).val();
$.ajax({
键入:“获取”,
url:produtos.php,
数据:(filtto:id),
数据类型:“json”,
成功:功能(obj){
$('#message')[0]。value=filtro
}
}
});
}
但什么也没发生
这是正在开发的页面:
在select的onchange事件中,您可以编写javascript来发布表单并读取服务器端的select选项,但首先要设置($\u post['filtro']),然后在大括号内编写有意义的代码来处理该选项 如果您想在文章中保持select选项的状态,那么必须编写javascript函数,在页面加载后(靠近结束标记)设置select选项的selectedIndex这个js将由服务器在post操作时重新设计,它将输出js以根据用户选择的内容选择适当的索引。应在2分钟内发布代码。。 代码如下:
<html><body>
<form action="produtos.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<select name="filtro" id="filtro" >
<option value="0">Popularidade</option>
<option value="1">A-Z</option>
<option value="2">Z-A</option>
</select>
</form>
<script type="text/javascript" language="javascript">
document.getElementById('filtro').onchange=function(){
document.getElementById('form1').submit();
}
function setSelected(value){
var filtro = document.getElementById('filtro');
var options = filtro.options;
for(var i=0;i<options.length;i++){
if(options[i].value == value){
filtro.selectedIndex = i;
}
}
}
</script>
<?php
if(isset($_POST['filtro'])){
$selectedValue = $_POST['filtro'];
// code to process the data
//...
// code to remember dropdown
echo "<script type='text/javascript'>setSelected($selectedValue)</script>";
}
?>
</body>
</html>
大众化
A-Z
Z-A
document.getElementById('filtro')。onchange=function(){
document.getElementById('form1').submit();
}
选择的函数(值){
var filtro=document.getElementById('filtro');
var options=filtro.options;
对于(var i=0;iyou可以将要保留的变量传递给隐藏的表单字段,并在页面刷新时使用post方法检索它们
<html><body>
<form action="produtos.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<select name="filtro" id="filtro" >
<option value="0">Popularidade</option>
<option value="1">A-Z</option>
<option value="2">Z-A</option>
</select>
</form>
<script type="text/javascript" language="javascript">
document.getElementById('filtro').onchange=function(){
document.getElementById('form1').submit();
}
function setSelected(value){
var filtro = document.getElementById('filtro');
var options = filtro.options;
for(var i=0;i<options.length;i++){
if(options[i].value == value){
filtro.selectedIndex = i;
}
}
}
</script>
<?php
if(isset($_POST['filtro'])){
$selectedValue = $_POST['filtro'];
// code to process the data
//...
// code to remember dropdown
echo "<script type='text/javascript'>setSelected($selectedValue)</script>";
}
?>
</body>
</html>