Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.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
Javascript 使用来自ajax调用的js var更新php var_Javascript_Php_Jquery_Ajax - Fatal编程技术网

Javascript 使用来自ajax调用的js var更新php var

Javascript 使用来自ajax调用的js var更新php var,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我正试图用jQuery$.get()更新php$questNumber,使用递增的javascriptquestNum Console.log告诉我jsquestNumvar正确递增 但是echo“测试…”$任务编号输出1即使在我增加了JS端的值之后。这意味着更新后的值不会发送到$questNumber以更新数据库,并将适当的新值集返回到javascript端 JavaScript: /*Check player sentence input to see if grammar is corre

我正试图用jQuery
$.get()更新php
$questNumber
,使用递增的javascript
questNum

Console.log告诉我js
questNum
var正确递增

但是
echo“测试…”$任务编号输出
1
即使在我增加了JS端的值之后。这意味着更新后的值不会发送到
$questNumber
以更新数据库,并将适当的新值集返回到javascript端

JavaScript:

/*Check player sentence input to see if grammar is correct*/
function submitMe() {
    var input = document.getElementById('textBox').value;
    log(questNum);
    if ($.trim(input) == getSentence(questNum)) {
        $("#responseVerify").html("Great job");
        $("#textBox").val("").trigger("change");
        //post successful quest to Quests.php, which will increment questcount there, and get new vocab words
        questNum++;
        log(questNum);
        $.get("php/Quests.php", { "_questNum" : questNum},
            function() {
                $(".wordBank_Words").empty();
                $.each(wordsArray, function(key, value) {           
                    $(".wordBank_Words").append("<div class='bank-word' word='" + key + "' ><b>" + key + "</b>: " + value + "</div>");
                });
            });
        }
    else {
        $("#responseVerify").html("Keep going...");
    }
}
/*检查播放器的句子输入,看看语法是否正确*/
函数submitMe(){
var input=document.getElementById('textBox')。值;
log(questNum);
if($.trim(输入)=getSession(questNum)){
$(“#responseVerify”).html(“干得好”);
$(“#文本框”).val(“”.trigger(“更改”);
//将成功的任务发布到Quests.php,这将增加那里的任务数,并获得新的词汇
questNum++;
log(questNum);
$.get(“php/Quests.php”,{“\u questNum”:questNum},
函数(){
$(“.wordBank_Words”).empty();
$.each(字数组,函数(键,值){
$(“.wordBank_Words”)。追加(“+key+”:“+value+”);
});
});
}
否则{
$(“#responseVerify”).html(“继续…”);
}
}
PHP:

试试这种ajax格式

$.ajax({                                  
        type: "GET",   //method
        url:"php/Quests.php", //your ajax page        
        data:"_questNum="+questNum,  //pass values to this data
        success: function(data){    //success function  
        alert('sasas');        
        }

在页面顶部回显您的$\u GET[''u questNum',并向我显示其余Javascript将有所帮助,因为所讨论的变量在nature@NathanSrivi这就给了
未定义的索引:_questNum
@Growler这是你的问题。您没有将变量传递给PHP
$questNumber=(isset($\u-GET[''''''])?($\u-GET[''''']):1)
删除最后一个
就在最后一个
$\u获取
并在
之前添加一个
Nathan,它成功地发出了警报,但似乎没有将var传递给php。
        <!--ROW 3: RESPONSE-->
        <div class="row">
            <div class="span12">
                <!--Select a word shown and it gets added to the input box-->
                Create sentence:

                <input type="text" id="textBox"  value="" />
                <br/>
                <button onclick="submitMe()" id="testButton" >Submit Response </button>
                <br/>

                <i><span id="responseVerify"></span></i><br />
                <div class="wordBank_Headings">Word Bank:
                    <span class="wordBank_Words"></span>
                </div>
                <div class="wordBank_Headings">Hint:
                    <span class="wordBank_Hint"></span>
                </div>
                <div class="wordBank_Headings">New Words:
                    <span class="new"></span>
                </div>
            </div>
        </div>
$.ajax({                                  
        type: "GET",   //method
        url:"php/Quests.php", //your ajax page        
        data:"_questNum="+questNum,  //pass values to this data
        success: function(data){    //success function  
        alert('sasas');        
        }