通第二「選擇」值這是阿賈克斯的數據從另一個頁面進來:URL不會從阿賈克斯輸入
<? $cat=strval($_GET['cat']);
//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die("Unable to select database");
}
$query="SELECT * FROM cats WHERE cat_id='$cat'";
$result=mysql_query($query);
?>
<select name="sub_cat">
<option>Select Sub-Category</option>
<? while($row2=mysql_fetch_array($result)) { ?>
<option value="<?=($row2['sub_cat_id'])?>"><?=$row2['sub_cat']?></option>
<? } ?></select>
這是其上顯示的頁面:
<select name="cat" onChange="getSub_cat(this.value)">
<option>Select Category</option>
<?php
//Open database connection
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die("Unable to select database");
}
//Select categories
$sql = "SELECT DISTINCT cat, cat_id FROM cats ";
$rs = mysql_query($sql);
while($row = mysql_fetch_array($rs))
{
echo "<option value=\"".$row['cat_id']."\">".$row['cat']."</option>\n ";
}
?>
</select>
<b>Sub-Category</b></td>
<div id="sub_catdiv"><select name="sub_cat" id="sub_cat"></div>
<option>Select Category First</option>
</select>
</div>
,這是它通過的URL:
https://mysitewontworkcom/somepagephp?state=state&cat=cat&submit=submit
從ajax拉入表單的sub_cat根本不會顯示在URL中!
「狀態」(在形式中較早)和「貓」拉好? 任何想法?請幫忙!
function getXMLHTTP() { //function to return the xml http object
var xmlhttp=false;
try{
xmlhttp=new XMLHttpRequest();
}
catch(e) {
try{
xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e1){
xmlhttp=false;
}
}
}
return xmlhttp;
}
function getSub_cat(cat_id) {
var strURL="findCat.php?cat="+cat_id;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('sub_catdiv').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
你是什麼意思,不會通過?你如何得到這個網址?它是表單提交網址還是? – 2015-02-07 22:36:17
這是傳遞到下一頁的URL,我需要選擇的sub_cat通知它甚至不說sub_cat = – 2015-02-07 22:37:27
是的,它的表單提交@BardhLohaj – 2015-02-07 22:40:12