我正在尝试为我一直在处理的投票脚本构建一个主题构建器。我正在尝试这样做,以便您可以查看预览,因此不希望页面重新加载。我对 AJAX 很陌生,如果我绕过它,一切似乎都可以工作。
问题是当我调用 php 文件来更新我的数据库时出现错误
HTML 文件:(所有的输入实际上都在 index.php 中,但为了篇幅,这里没有包含它)
<div id="theme" name="theme" class="theme">
<form class="css_form">
<table>
<tr>
<td align="left" valign="center"><label>Map Navigation Color</label></td>
<td align="left" valign="center"><input type="text" id="map_navigation" name="map_navigation" class="colorwell" value="#ffffff" /></td>
</tr>
<tr>
<td align="left" valign="center"><label>Test It</label></td>
<td align="left" valign="center"><input type="button" value="preview" onClick="getTheme();"></td>
</tr>
</table>
</form>
</div>
AJAX 文件 (theme_builder.js)
function getTheme(str)
{
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("theme").innerHTML=xmlhttp.responseText;
}
}
var button_style = document.getElementById('button_style').value;
var div_grad_1 = document.getElementById('div_grad_1').value;
var div_grad_2 = document.getElementById('div_grad_2').value;
var gradient_direction = document.getElementById('gradient_direction').value;
var map_0 = document.getElementById('map_0').value;
var map_100 = document.getElementById('map_100').value;
var map_selected = document.getElementById('map_selected').value;
var map_outline = document.getElementById('map_outline').value;
var map_navigation= document.getElementById('map_navigation').value;
var queryString =
"button_style=" + button_style +
"&div_grad_1=" + div_grad_1 +
"&div_grad_2=" + div_grad_2 +
"&gradient_direction=" + gradient_direction +
"&map_0=" + map_0 +
"&map_100=" + map_100 +
"&map_selected=" + map_selected +
"&map_outline=" + map_outline +
"&map_navigation=" + map_navigation;
xmlhttp.open("GET", "theme_builder.php?"+queryString, true);
xmlhttp.send();
}
最后是 php 文件(theme_builder.php
<?php
include('../../connection.php');
$button_style = ($_GET['button_style']);
$div_grad_1 = ($_GET['div_grad_1']);
$div_grad_2 = ($_GET['div_grad_2']);
$gradient_direction = ($_GET['gradient_direction']);
$map_0 = ($_GET['map_0']);
$map_100 = ($_GET['map_100']);
$map_selected = ($_GET['map_selected']);
$map_outline = ($_GET['map_outline']);
$map_navigation = ($_GET['map_navigation']);
$id='2';
$update_settings = "UPDATE vs_vote_settings SET
button_style = ?,
div_grad_1 = ?,
div_grad_2 = ?,
gradient_direction = ?,
map_0 = ?,
map_100 = ?,
map_selected = ?,
map_outline = ?,
map_navigation = ?
WHERE id=?";
$query_update_settings = $conn->prepare($update_settings);
if(!$query_update_settings)
{
die ("error" .$conn->errorInfo());
}
$query_update_settings->execute(array($button_style, $div_grad_1, $div_grad_2, $gradient_direction, $map_0, $map_100, $map_selected, $map_outline, $map_navigation, $id));
$conn = null;
?>
我得到的错误是:
Notice: Undefined index: div_grad_2 in C:\Program Files (x86)\EasyPHP-12.0\www\my portable files\status201\applications\201vote\theme_builder.php on line 6
Notice: Undefined index: gradient_direction in C:\Program Files (x86)\EasyPHP-12.0\www\my portable files\status201\applications\201vote\theme_builder.php on line 7
Notice: Undefined index: map_0 in C:\Program Files (x86)\EasyPHP-12.0\www\my portable files\status201\applications\201vote\theme_builder.php on line 8
Notice: Undefined index: map_100 in C:\Program Files (x86)\EasyPHP-12.0\www\my portable files\status201\applications\201vote\theme_builder.php on line 9
Notice: Undefined index: map_selected in C:\Program Files (x86)\EasyPHP-12.0\www\my portable files\status201\applications\201vote\theme_builder.php on line 10
Notice: Undefined index: map_outline in C:\Program Files (x86)\EasyPHP-12.0\www\my portable files\status201\applications\201vote\theme_builder.php on line 11
Notice: Undefined index: map_navigation in C:\Program Files (x86)\EasyPHP-12.0\www\my portable files\status201\applications\201vote\theme_builder.php on line 12
请注意, button_style 和 div_grad_1 不会引发错误,但其余的是。我找不到错误,但我认为它与我的 ajax 文件有关。我按照Tizag For the Ajax 文件的教程进行操作,并尝试根据我的需要对其进行修改...
任何帮助将不胜感激,我知道这里有大量代码,但我已经被难住了一段时间。
谢谢