AJAX不发送参数超过 [英] AJAX not sending parameters over

查看:111
本文介绍了AJAX不发送参数超过的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会开门见山地说。

我有AA列表,显示大家在谁已经证实他们将参加比赛的分贝。我想列表,这取决于组从选择框中选择更改。

I have a a list which shows everyone in the db who has confirmed that they'll be attending a match. I want the list to change depending on what group is chosen from a select box.

这是我到目前为止有: HTML和放大器; AJAX

Here's what I have so far: html & AJAX

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

            <form>
            <select name="users" onchange="showUser(this.value)">
              <option value="">Select a group:</option>
              <option value="CMA">CMA</option>
              <option value="CM1">CM1</option>
              <option value="CP2">CP2</option>
              <option value="CBBC">CBBC</option>
              </select>
            </form>
            <br>
            <div id="attendYes"><b>Person info will be listed here...</b></div>

            </body>
            </html>

这里是 attending.php 的选择,就是要发送到页面:                 

And here is the 'attending.php' page that the choice is meant to be sent to:

            <?php
            $q = intval($_GET['q']);

            $con = mysqli_connect('-----','-----','-----','-----');
            if (!$con) {
                die('Could not connect: ' . mysqli_error($con));
            }

            mysqli_select_db($con,"handsomejack_co_forms");
            $sql="SELECT * FROM stats WHERE activity='".$q."' AND attend='0' ORDER BY username ASC";
            $result = mysqli_query($con,$sql);

            echo "<table>
            <tr>
            <th>User</th>
            </tr>";
            while($row = mysqli_fetch_array($result)) {
                echo "<tr>";
                echo "<td>" . $row['username'] . "</td>";
                echo "</tr>";
            }
            echo "</table>";
            mysqli_close($con);
            ?>

我已经改变从SQL。$ Q。为定义的选择 - 像CMA - 和它的工作,所以我知道这个问题是来自发送q超过

I have changed the sql from ".$q." to a defined choice - like CMA - and it worked, so I know the issue comes from sending q over.

任何想法可能是什么问题?

Any ideas as to what could be the problem?

干杯。

推荐答案

有<打击>两个三样东西,我建议:

一个。)
更改目标div的ID。你有 attendYes 键,您使用的是 txtHint

A.)
Change the id of the target div. as you have attendYes and you are using txtHint.

乙。)@ JS
您可以尝试发送查询的。发送()如下图所示。

B.) @ js
You can try sending the query in the .send() like below.

xmlhttp.open("GET","attending.php",true);
xmlhttp.send("q=" + encodeURIComponent(str));

C)和@ PHP的:

C.) and @ php:

您不应使用 INTVAL()虽然我不是很擅长的PHP,但按文件是别的东西。所以我建议你可以改变:

You should not use intval() although i am not very good at php but as per documentation it is something else. so i suggest you to change this:

$q = intval($_GET['q']);

这样:

$q = $_GET['q'];

这篇关于AJAX不发送参数超过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆