0

ajaxで変数をphpに送信しようとしています。

js:

var test1 = "test"
$.ajax({
    type : "POST",
    url : "getid.php",
    data:  {test1 : test1},
    success: function() {
         console.log("message sent!");
    }
}); 

「メッセージを送信しました!」コンソールに出てくる

php:

<?php 
$test1 = $_POST['test1'];
echo $test1; 
?> 

エラーメッセージ:

Notice: Undefined index: test1...

ここで何が間違っているのか本当にわかりません...何かアイデアはありますか?

` を実行するときの UPDATE*

$.ajax({    
        type : "POST",
        url : "getid.php",
        data:  {"test1" : test1},
        success: function(msg) {
            console.log("message sent!");
            console.log(msg);
        }
}); 

これは「テスト」をログに記録します

それでもphpで同じエラーが発生します..

4

2 に答える 2

2

jQuery コードを変更します。

var test1 = "test"
$.ajax({
    type : "post",
    url : "getid.php",
    data:  {"test1" : test1}, // this is the row that was causing the problem
    success: function(msg) {
         console.log(msg);
    }
}); 

test1「test」を含む定義済み変数であり、データが{"test":"test"}

于 2013-07-07T17:15:59.967 に答える