1

以前にこれを行ったことがありますが、何らかの理由でパラメーターが奇妙に渡されています。

パラメータを渡すために使用したJavaScript関数があり、いくつかのテストを実行しましたが、関数内の変数は正しいです。

これらは、問題に関連する js のほんの一部です。

var tdes = document.getElementById("taskDescription1").value;
var tnam = document.getElementById("taskName1").value;
var shif = document.getElementById("shift1").value;
var ttyp = document.getElementById("taskType1").value;
var date = document.getElementById("datepicker").value;
var ooc = document.getElementById("ooc1").value;
var dateSplit = date.split('/');
var deadlineDate = "";



for( var i = 0; i < dateSplit.length; i++){
deadlineDate = deadlineDate + dateSplit[i]; 
}
xmlhttp.open("GET","subTask.php?q="+ encodeURIComponent(tdes) + "&w=" + encodeURIComponent(tnam) +"&e=" +encodeURIComponent(shif) + "&y=" + encodeURIComponent(ttyp) + "&b=" + encodeURIComponent(deadlineDate) + "&u=" + encodeURIComponent(ooc),true);

私はWebコンソールを実行しましたが、これが実際に渡されているものです...

http://***************/****/********/subTask.php?taskName1=test+taskname+works&taskDescription1=test+des&shift1=All&ooc1=Open&taskType1=normal&datepicker=06%2F28%2F2013

PHPのxmlhttp.openとGETメソッドの間で何が起こっているのかわかりません。これらの変数はどれも渡されません。

4

2 に答える 2

0

次のスクリプトが役立ちます。

function ajaxObj( meth, url ) 
{   
var x = false;
if(window.XMLHttpRequest)
    x = new XMLHttpRequest();
else if (window.ActiveXObject) 
    x = new ActiveXObject("Microsoft.XMLHTTP");  
x.open( meth, url, true );
x.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
return x;
}
function ajaxReturn(x){
    if(x.readyState == 4 && x.status == 200){
        return true;    
    }
}

    var ajax = ajaxObj("POST", "subTask.php");
    ajax.onreadystatechange = function() {
        if(ajaxReturn(ajax) == true) {
           console.log( ajax.responseText )
        }
    }
    ajax.send("u="+tdes+"&e="+tnam+ ...... pass all the other 'n' data );
于 2016-01-18T12:52:25.020 に答える
0

jQuery を使用しない理由 - 非常に単純な形式 (私は POST を好む...):

$(document).ready(function() {
    var tdes = $("#taskDescription1").val();
    var tnam = $("#taskName1").val();
    var shif = $("#shift1").val();
    var ttyp = $("#taskType1").val();
    var date = $("#datepicker").val();
    var ooc = $("#ooc1").val();
    var dateSplit = date.split('/');
    var deadlineDate = "";

    for( var i = 0; i < dateSplit.length; i++){
        deadlineDate = deadlineDate + dateSplit[i]; 
    }

    $.ajax({
        type: "POST",
        url: "subTask.php",
        data: "q="+ encodeURIComponent(tdes) + "&w=" + encodeURIComponent(tnam) +"&e=" +encodeURIComponent(shif) + "&y=" + encodeURIComponent(ttyp) + "&b=" + encodeURIComponent(deadlineDate) + "&u=" + encodeURIComponent(ooc),true),
        success: function(whatigot) {
            alert('Server-side response: ' + whatigot);
        } //END success fn
    }); //END $.ajax

}); //END document.ready()

コールバック関数の記述がいかに簡単であるかに注意してくださいsuccess... alert() の例で見られるように、subTask.php によって返されるものはすべてその関数内で使用可能になります。

<head>タグに jQuery ライブラリを含めることを忘れないでください。

<head>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
</head>

また、次の行をファイルの先頭に追加して、subTask.php何が起こっているかを確認します。

<?php
    $q = $_POST["q"];
    $w = $_POST["w"];
    die("Value of Q is: " .$q. " and value of W is: " .$w);

q=との値はw=警告ボックスで返されるので、(少なくとも) subTask.php が受け取ったときに含まれていた値を確認できます。

于 2013-06-18T21:56:14.790 に答える