AJAX + PHP自生成字段产生空白结果 [英] AJAX + PHP self-generated fields producing blank results
问题描述
我回来了,这可能有点棘手,但我们会发现的! :D
I'm back and this one might be a little tricky but we will find out! :D
好的,我使用php来自动填充select
字段,因此当新的代理加入时,我不必不断更新options
.我在页面的此部分使用ajax(javascript),除了公司的select
字段,我对此没有任何问题.
Okay I am using php to self populate my select
fields so I don't have to continuously update the options
when new agents join. I am using ajax (javascript) for this part of the page and I have had no problems with this except with the company select
field.
我的所有select
字段都可以正常工作,但Company字段仅对似乎有&"字样的公司不显示任何内容.在名字里. (两家公司仍然使用名称&")
All my select
fields work with out any problems but the Company field which will display nothing only on companies that seem to have "&" in the name. (Two companies still work with "&" in the name)
无法运作的公司列表:
-国歌
-Bogart
-伯纳姆
-教堂保险
-福塞特
-JRM
-肯尼思·布朗(Kenneth B.Brown)
-牛顿
-Sam F.
-谢里尔
-华莱士&特纳
List of non-functioning Companies:
-Anthem
-Bogart
-Burnham
-Church Insurance
-Fawcett
-JRM
-Kenneth B. Brown
-Newton
-Sam F.
-Sherrill
-Wallace & Turner
PHP公司select
代码:(公司字段中的if/else语句理想情况下为if ($row['Company'] !== NULL) {
echo '<option value="'.$row['Company'].'">'.$row['Company'].'</option>';
}
,但由于某些原因,它将在option
下拉列表的空白处回显.)
PHP Company select
code: (The if/else statement in the companies field would ideally be if ($row['Company'] !== NULL) {
echo '<option value="'.$row['Company'].'">'.$row['Company'].'</option>';
}
but for some reason it will echo in a blank space in the option
dropdown.)
<label for="company">Company</label><br />
<select id="company" name="users" onChange="showUser(this.value)">
<?php include 'login.php';
$result = mysqli_query($con, "SELECT DISTINCT Company FROM `roster` ORDER BY Company ASC;");
echo '<option value="">' . 'Select a Company' .'</option>';
while ($row = mysqli_fetch_array($result)) {
if ($row['Company'] == NULL) {
}
else {
echo '<option value="'.$row['Company'].'">'.$row['Company'].'</option>';
}
}
?>
</select>
PHP用于其他select
字段:
PHP for other select
fields:
<label for="last">Last Name</label><br />
<select id="last" name="Last_Name" onChange="showUser(this.value)">
<?php include 'login.php';
$result = mysqli_query($con, "SELECT DISTINCT Last_Name FROM `roster` ORDER BY Last_Name ASC;");
echo '<option value="">' . 'Select an Agent' .'</option>';
while ($row = mysqli_fetch_array($result)) {
echo '<option value="'.$row['Last_Name'].'">'.$row['Last_Name'].'</option>';
}
?>
</select>
对此有任何想法吗?如果您需要查看在结果中回显的process.php页面,请问一下!感谢一百万为您提供帮助的人.
Any Ideas on this one? If you need to see the process.php page which echos in the results then just ask! Thanks a million to anyone who helps out.
通过php填充HTML时的外观:
How the HTML looks when populated through php:
<select id="company" name="users" onchange="showUser(this.value)">
<option value="">Select a Company</option><option value="A.R.T. Group">A.R.T. Group</option><option value="ALPHA Benefits">ALPHA Benefits</option>
</select>
我只列出了几条,因为其中有80条是一大行html.
I only included a few since 80ish of them is one massive line of html.
推荐答案
您需要 urlencode 通过ajax传递的参数. &符告诉PHP $_GET['q']
已完成,并且新的$_GET
变量正在启动.
You need to urlencode the parameter that is being passed via ajax. The ampersand is telling PHP that $_GET['q']
is complete and a new $_GET
variable is starting.
注意%26
的&"号将返回所需的结果.
Notice the %26
for the ampersand returns the desired result.
http://healthbenefitsohio.com/process.php?q = Anthem%20Blue%20Cross%20%26%20Blue%20Shield
您的公司选项应如下所示:
Your company options should look like this:
echo '<option value="'.urlencode($row['Company']).'">'.$row['Company'].'</option>';
出于良好的考虑,我还将对显示内容进行编码
For good measure, I would also encode the display
echo '<option value="'.urlencode($row['Company']).'">'.htmlspecialchars($row['Company'],ENT_QUOTES).'</option>';
这篇关于AJAX + PHP自生成字段产生空白结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!