Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
理解ajaxphp脚本进行线索游戏练习_Php_Jquery_Ajax - Fatal编程技术网

理解ajaxphp脚本进行线索游戏练习

理解ajaxphp脚本进行线索游戏练习,php,jquery,ajax,Php,Jquery,Ajax,我试图理解我想要运行以跟踪进度的PHP脚本与已经发生的前端工作之间的关系。这是一个游戏练习中的两条线索。一旦线索输入正确,一切都会发生,如下所示,我想添加一个发送到MYSQL的脚本 我现在正在写剧本,但我想知道在什么时候我会介绍这个。在我的PHP中是否有我需要的东西来区分它是AJAX。就像在后台运行它一样?我是否只是将其作为另一个更大的PHP脚本的一部分来“包含”呢 我心目中的脚本如果正确将发送1,如果仍然错误将发送0。这样我就可以很容易地确定,而不必处理线索。这些线索在我看来无关紧要,但你对此

我试图理解我想要运行以跟踪进度的PHP脚本与已经发生的前端工作之间的关系。这是一个游戏练习中的两条线索。一旦线索输入正确,一切都会发生,如下所示,我想添加一个发送到MYSQL的脚本

我现在正在写剧本,但我想知道在什么时候我会介绍这个。在我的PHP中是否有我需要的东西来区分它是AJAX。就像在后台运行它一样?我是否只是将其作为另一个更大的PHP脚本的一部分来“包含”呢

我心目中的脚本如果正确将发送1,如果仍然错误将发送0。这样我就可以很容易地确定,而不必处理线索。这些线索在我看来无关紧要,但你对此有何看法

// =====clue 1====================////////////////// clue 1 **************
//**********************************========================
$(document).on('click', '.btn-clue', function(){ 
    if($i!=1){
       $.ajax({
                  type: "POST",
                  url: "includes/post_clue_progress",
                  data: { clueTwo: "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
                $("#clueWrongTwo").hide();
                $("#mySecondDivClueTwo").remove();
                $("#clueTwo").remove();
                $("#clue2Input").remove();
                $two.show();
                $("#clueTwoInputCorrect").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);
        }
    }
});
// =====clue 2====================////////////////// clue 2*********=========
$(document).on('click', '.btn-clueTwo', 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 $two = $('#twoClueShow');
        var x = $("#clueTwoInput").find('input[type=text]').val();
        if(x == 'C' || x == 'CS') {
            // if answer correct you should load data from ajax 
                    // and append it to a container

            $("#clueWrongTwo").hide();
            $("#mySecondDivClueTwo").remove();
            $("#clueTwo").remove();
            $("#clue2Input").remove();
            $two.show();
            $("#clueTwoInputCorrect").slideDown('slow').show();
            $i++;
        } else {
        $("#mySecondDivClueTwo").remove();
        var mySecondDivClueTwo = $('<div id="mySecondDivClueTwo"><img src="images/check-x-mark.png" /></div>') .show('slow');
            $('#clueWrongTwo').append(mySecondDivClueTwo);
        }
    }
});
//====clue 1============================/////////////////clue 1**************
//**********************************========================
$(文档).on('click','.btn-clue',function(){
如果($i!=1){
$.ajax({
类型:“POST”,
url:“包括/发布线索/进度”,
数据:{cluewo:“1”,用户名线索:}
})
.done(函数(msg){
//msg是php脚本中的任何回显数据,或者以某种方式输出到屏幕
$(“#cluewrowtwo”).hide();
$(“#mysecondivcluetwo”).remove();
$(“#cluewo”).remove();
$(“#clue2Input”).remove();
$2.show();
$(“#clueTwoInputCorrect”).slideDown('slow').show();
$i++;
});   
}否则{
$(“#mysecondiv”).remove();
var mysecondiv=$('').show('slow');
$(“#clueErrorOne”).append(mySecondDiv);
}
}
});
//第二条线索第二条线索*********=========
$(文档).on('click','.btn cluewo',function(){
如果($i!=1){
//检查textbox是否具有所需的值(本例中为1),
//在应用程序中,将文本框值传递给
//这里是ajax,在服务器端进行检查
变量$two=$(“#two clueshow”);
var x=$(“#clueTwoInput”).find('input[type=text]').val();
如果(x='C'| | x=='CS'){
//如果答案正确,您应该从ajax加载数据
//并将其附加到容器中
$(“#cluewrowtwo”).hide();
$(“#mysecondivcluetwo”).remove();
$(“#cluewo”).remove();
$(“#clue2Input”).remove();
$2.show();
$(“#clueTwoInputCorrect”).slideDown('slow').show();
$i++;
}否则{
$(“#mysecondivcluetwo”).remove();
var mysecondivcluetwo=$('').show('slow');
$('#clueErrortwo').append(mySecondDivClueTwo);
}
}
});
以上就是我能得到的。这就是我感到困惑的地方。我现在想发送到数据库,通过AJAX正确回答了答案,对吗?我会在评论区中包含我的php脚本吗

我在考虑创建一个脚本,如果正确,则填充1,如果不正确,则填充0,以使生活更轻松。让这项工作完成,因为我不需要重新引入输入或重复使用。这样,一旦页面重新加载,我就无法再次输出输入,并使用这些信息来确定显示的内容以及它们在线索游戏中的位置。基本上节省了进度

在构建我的普通PHP时,是否有特定的用途。我想,在哪里“包括”它是我困惑的地方

我的按钮供参考

<div id="clueOneInput">
    <input type="text" id="clue1" class="clue-text form-control" placeholder="Enter Clue 1 here and check"/>
</div>
<input type="button" id="clue1Input"class="btn btn-primary btn-clue" value="Check">

更新:

// =====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",
                      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);
        }
    }
});
// =====clue 2====================////////////////// clue 2**********************************************************************========================
$(document).on('click', '.btn-clueTwo', function(){ 
    if($i!=1){
        var $two = $('#twoClueShow');
        var x = $("#clueTwoInput").find('input[type=text]').val();
        if(x == 'CS' || x == 'CSU')
        {
            $.ajax({
                      type: "POST",
                      url: "includes/post_clue_progress",
                      data: { clueTwo: "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
                    $("#clueWrongTwo").hide();
                    $("#mySecondDivClueTwo").remove();
                    $("#clueTwo").remove();
                    $("#clue2Input").remove();
                    $two.show();
                    $("#clueTwoInputCorrect").slideDown('slow').show();
                    $i++;
                  });   
        }
        else
        {
            $("#mySecondDivClueTwo").remove();
            var mySecondDivClueTwo=$('<div id="mySecondDivClueTwo"><img src="images/check-x-mark.png" /></div>').show('slow');
            $('#clueWrongTwo').append(mySecondDivClueTwo);
        }
    }
});
//====clue 1============================/////////////////clue 1**********************************************************************========================
$(文档).on('click','.btn-clue',function(){
如果($i!=1){
//检查textbox是否具有所需的值(本例中为1),
//在应用程序中,您将在此处将文本框值传递给ajax,并在服务器端进行检查
var$one=$(“#oneClueShow”);
var x=$(“#clueOneInput”).find('input[type=text]).val();
如果(x='d'| | x='dr')
{
//如果答案正确,您应该从ajax加载数据并将其附加到容器中
$.ajax({
类型:“POST”,
url:“包括/发布线索/进度”,
数据:{clueOne:“1”,usernameClue:}
})
.done(函数(msg){
//msg是php脚本中的任何回显数据,或者以某种方式输出到屏幕
$(“#clueErrorOne”).hide();
$(“#mysecondiv”).remove();
$(“#clueOne”).remove();
$(“#clue1Input”).remove();
$1.show();
$(“#clueOneInputCorrect”).slideDown('slow').show();
$i++;
});
}
其他的
{
$(“#mysecondiv”).remove();
var mysecondiv=$('').show('slow');
$(“#clueErrorOne”).append(mySecondDiv);
}
}
});
//第二条线索第二条线索**********************************************************************========================
$(文档).on('click','.btn cluewo',function(){
如果($i!=1){
变量$two=$(“#two clueshow”);
var x=$(“#clueTwoInput”).find('input[type=text]').val();
如果(x='CS'| | x='CSU')
{
$.ajax({
类型:“POST”,
url:“包括/发布线索/进度”,
数据:{cluewo:“1”,用户名线索:}
})
.done(函数(msg){
//msg是在php脚本中回显或输出到s的任何数据
$.ajax({
  type: "POST",
  url: "yourScriptToUpdateDB.php",
  data: { clue: "Wrong", user: "JoeBob" }
})
  .done(function( msg ) {
    // msg is any data that is echoed in the php script or output to screen is some way
    $("#clueWrongOne").hide();
  });