weixin_33676492 2018-07-31 12:06 采纳率: 0%
浏览 33

在Wordpress上使用Ajax和MySQL

I'm trying to branch out into Ajax calls for some of my MySQL queries on a Wordpress site I run. To do this I've been following the example here.

I haven't modified the javascript component, only the form and then I'm using a very simple snippet of php to see if $q is getting fed to php or not.

On page startup I'm getting the correct echo ALL however on selecting anything in the dropdown menu I'm finding that there is no change in the echo of $q.

What am I missing here? I'm using Google Chrome as my browser if that is an issue.

<html>
<head>
<script type="text/javascript">
function showUser(str) {
    if (str == "") {
        document.getElementById("txtHint").innerHTML = "";
        return;
    } else { 
        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 (this.readyState == 4 && this.status == 200) {
                document.getElementById("txtHint").innerHTML = this.responseText;
            }
        };
        xmlhttp.open("GET","getuser.php?q="+str,true);
        xmlhttp.send();
    }
}
</script>
</head>
<body>

<form>
<select name="users" onchange="showUser(this.value)">
  <option value="">Select a team:</option>
  <option value="HAW">Hawks</option>
  <option value="GEE">Cats</option>
  <option value="ADE">Crows</option>
  <option value="WCE">Eagles</option>
  </select>
</form>
<br>
<div id="txtHint"><b>Team info will be listed here...</b></div>

</body>
</html>

My simple php code is:

$q = $_GET['q'] ?: 'ALL';
echo $q;
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
    • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
    • ¥15 可见光定位matlab仿真
    • ¥15 arduino 四自由度机械臂
    • ¥15 wordpress 产品图片 GIF 没法显示