Php Ajax未发布到数据库
我正在学习AJAX,但在理解如何在页面外运行的脚本中抛出错误时遇到了困难。我无法获取更新数据库的数据,但似乎也无法获取错误。我不确定hwo在页面外运行时是否会像在这个AJAX场景中那样进行转储和调试。我是AJAX新手,所以问题也可能存在。jquery中是否有使用AJAX来确定这一点的等价物Php Ajax未发布到数据库,php,jquery,ajax,Php,Jquery,Ajax,我正在学习AJAX,但在理解如何在页面外运行的脚本中抛出错误时遇到了困难。我无法获取更新数据库的数据,但似乎也无法获取错误。我不确定hwo在页面外运行时是否会像在这个AJAX场景中那样进行转储和调试。我是AJAX新手,所以问题也可能存在。jquery中是否有使用AJAX来确定这一点的等价物 ***Update** <?php if (!empty($_POST['clueOne'])) { include "includes/db_conx.php";
***Update**
<?php
if (!empty($_POST['clueOne'])) {
include "includes/db_conx.php";
$usernameClue = mysqli_real_escape_string($db_conx, $_POST['usernameClue']);
$clueOne = mysqli_real_escape_string($db_conx, $_POST['clueOne']);
// See if that product name is an identical match to another product in the system
// Add this product into the database now
$sqls = "UPDATE usersClueGame SET clueOne = '1' WHERE username = $usernameClue;";
$result = mysqli_query($db_conx,$sqls) or die("Couldn't execute query.");;
exit();
}
?>
***更新**
您需要$usernameClude
在sql语句中,$username
似乎未定义。请使用浏览器的开发工具确定AJAX调用使用的URL(检查“网络”选项卡),并将该URL粘贴到浏览器的地址栏中。查看返回的结果和/或错误消息,并将其与JS期望的结果进行比较。如果没有显示错误或数据,请检查您的php.ini文件并更正您的错误报告和显示错误设置。感谢您发现@jeroen。这实际上是我为了更好的理解而改变的。这对我来说是正确的。你应该在这里发布你的真实代码,否则将很难帮助你,特别是如果你引入了不在原始代码中的错误。@GeorgeCummins parameters clueOne 1 username提示chris似乎都很好。AJAX调用的URL是正确的。post_clue_progress.php正在正确运行。
// =====clue 1====================////////////////// clue 1**********************************************************************========================
$(document).on('click', '.btn-clue', function(){
if($i!=1){
//checking if textbox has desired value (1 in this case),
//in your application you would be passing the textbox value to ajax here and making the check at server side
var $one = $('#oneClueShow');
var x = $("#clueOneInput").find('input[type=text]').val();
if(x == 'd' || x == 'dr')
{
//if answer correct you should load data from ajax and append it to a container
$.ajax({
type: "POST",
url: "includes/post_clue_progress.php",
data: { clueOne: "1", usernameClue: "<?php echo $manager; ?>" }
})
.done(function( msg ) {
// msg is any data that is echoed in the php script or output to screen is some way
$("#clueWrongOne").hide();
$("#mySecondDiv").remove();
$("#clueOne").remove();
$("#clue1Input").remove();
$one.show();
$("#clueOneInputCorrect").slideDown('slow').show();
$i++;
});
}
else
{
$("#mySecondDiv").remove();
var mySecondDiv = $('<div id="mySecondDiv"><img src="images/check-x-mark.png" /></div>').show('slow');
$('#clueWrongOne').append(mySecondDiv);
}
}
});