我想改变:
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","get_content.php?q="+str,true);
xmlhttp.send();
}
进入 jQuery ajax。现在我有以下实现:
$('#menurow').change(function () {
$.ajax({
type: "GET",
url: "get_content.php?q="+str,true,
data: $('#txtHint').innerHTML(),
success: function(data) {
alert('test');
}
})
});
当我尝试这段代码时,浏览器一直说 Uncaught SyntaxError: Unexpected identifier on data: $('#txtHint').innerHTML()
。有人知道如何解决这个问题吗?这是 html/php 代码:
<form>
<select name="menurow" id="#menurow">
<option value ="select">Selecteer een menu</option>
<?php
$sql= mysql_query("SELECT * FROM Menu") or die(mysql_error());
while ($row = mysql_fetch_array($sql))
{
?><option data="menu" value="<?php echo $row['menu_id']; ?>"><?php echo $row['menu_name']; ?></option>
<?php
$subsql= mysql_query("SELECT * FROM SubMenu INNER JOIN Menu WHERE SubMenu.menu_id = Menu.menu_id AND Menu.Menu_id = ".$row['menu_id']."") or die(mysql_error());
while ($subrow = mysql_fetch_array($subsql))
{
?><option data="submenu" value="<?php echo $subrow['submenu_id']; ?>"><?php echo "--".$subrow['submenu_name']; ?></option>
<?php
}
}
?>
</select>
</form>
<div id="txtHint"></div>
提前致谢
谢谢你们的帮助。现在我有它如下:
$('.menurow').change(function(str) {
$.ajax({
type: "GET",
url: "get_content.php?q="+str,
success: function(data) {
$('#txtHint').html(data);
tinyMCE.init({
theme : "advanced",
mode : "textareas"
});
}
})
});
如何在其中获取表单的数据?我已经在函数中声明了 str 。因此,它显示空字段。我怎样才能用数据填充它们?