1

我正在使用此功能来显示在我的表单中选择的值。结果在我的页面上正确显示,但没有任何内容发送到我的 getlist.php 页面。

有人可以帮我吗?

jQuery代码:

function showValues() {
    var str = $("form").serialize();
    $("#results").text(str);
}

$(":checkbox, :radio").click(showValues);
$("select").change(showValues);
showValues();

$.post("getlist.php", $("form").serialize());

HTML:

<p><tt id="results"></tt></p>

这是我的表格

<form id="Moteur" onchange="testMoteur()">
<table cellspacing="0" cellpadding="5" bgcolor="#Be9e55">
<tr height="30px">
<td align="right">Marques : </td>
<td><? include ("marques.php"); ?></td>
</tr>
</table>
</form>

和 marques.php 代码

<select name="marques" id="marques" multiple="multiple">
<?
//<option value="x">Toutes les marques :</option>
?>
<?
mysql_connect("","",""); 
mysql_select_db(""); 
$query = mysql_query("SELECT * FROM marque WHERE flag_montre=1 ORDER BY nom ASC");
while ($myrow = mysql_fetch_row($query)) {
$id_marque=$myrow[0];
//test si marque est vide
$res3=mysql_query("SELECT * FROM montre WHERE id_marque=$id_marque AND id_etat=3");
$nbreLignes = mysql_num_rows($res3);
if ($nbreLignes==0){
}
else {  
echo "<option value='".$myrow[0]."'>".$myrow[1]." (".$nbreLignes.")</option>"; 
} 
} 
                    ?>
</select>

我刚刚更新了我的脚本,在 Firefox 上一切正常,但在 ie8 中没有任何反应(0 个错误)。该脚本的目标是将数组中的 vars 发送到我的 getlist.php

function SendMoteur() {

var xmlhttp = "";
var url = "";

// For modern browsers
if(window.XMLHttpRequest) {
    xmlhttp = new XMLHttpRequest();

// for IE 5/6
} else {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}

//  Rebuild the array of selected option boxes
marques = document.getElementById("marques");
for(var i=0; i < marques.length; i++) {
    if(marques[i].selected) {
        // Note the [] after the name
        url += "&marques[]=" + marques[i].value;
    }
}

 fourchettes = document.getElementById("fourchettes");
for(var i=0; i < fourchettes.length; i++) {
    if(fourchettes[i].selected) {
        // Note the [] after the name
        url += "&fourchettes[]=" + fourchettes[i].value;
    }
}

mouvements = document.getElementById("mouvements");
for(var i=0; i < mouvements.length; i++) {
    if(mouvements[i].selected) {
        // Note the [] after the name
        url += "&mouvements[]=" + mouvements[i].value;
    }
}

boitiers = document.getElementById("boitiers");
for(var i=0; i < boitiers.length; i++) {
    if(boitiers[i].selected) {
        // Note the [] after the name
        url += "&boitiers[]=" + boitiers[i].value;
    }
}

bracelets = document.getElementById("bracelets");
for(var i=0; i < bracelets.length; i++) {
    if(bracelets[i].selected) {
        // Note the [] after the name
        url += "&bracelets[]=" + bracelets[i].value;
    }
}


xmlhttp.open("GET","getlist.php?" + url, false);
xmlhttp.send();

if (xmlhttp.status == 200) {
    document.getElementById("txtHint2").innerHTML = xmlhttp.responseText;
} else {
    return false;
}

return false;
}
</script>
4

2 回答 2

0

这是正确的 jQuery 表单,试试这个:

$.post("getlist.php", $("#form").serialize());

或者如果这是一个表单类,试试这个:

$.post("getlist.php", $(".form").serialize());

此外,检查 getlist.php 文件是否与当前文件位于同一文件夹中。

于 2013-01-25T10:18:21.127 回答
0

你为什么不使用这个等价的:

为您的表格提供 id:form_id

function showValues() {
 var str = $("#form_id").serialize();
 $("#results").text(str);

 $.ajax({
  type: "POST",
  url: "getlist.php",
  data: {data: str},
 }).done(function(){
     alert('yiha, worked!');
 });
}
于 2013-01-25T10:21:08.407 回答