0

我的代码有点问题...

我有一个名为“listeclients.php”的页面,其中有几个带有 id 的客户端等。我只是做了一个小按钮,以便将一些数据发送到一个名为“actionclient.php”的页面,它只需要显示我发送到的参数它。actionclient.php 包括:

<?php
echo "test = ";
echo $_GET['test'];
echo $_GET['test2'];
?>

(这只是一个测试页)。

这是我的 jQuery 脚本:

$( "div.modif_dialog").click(function(e4) {
    $( "#editer" ).dialog("open");
    var monUrl4 = 'actionclient.php?action=modifier&id=';
    var url_final4 = monUrl4+pos4;
    $.ajax({
        type: "GET",
        url: url_final4,
        data: { test: "TEST", test2: pos4},
        success: function(){
           alert (pos4);
        }
    });
    $('#editer').load(monUrl4, function(response4, status4) {
        $('#test_dialog2').html(response4);
    });
    e4.preventDefault();
});

我的 alert(pos4) 警报效果很好,并且变量都是正确的。

actionclient.php (url_final4) 很好地加载到我的对话框中,但它总是只打印:“test =”

有什么线索吗?(我在另一个页面中使用 POST 方法完成了完全相同的代码,效果很好……我不明白。)

谢谢 !

4

3 回答 3

4

要查看发送的变量,您应该这样做:

....
success: function(data){
   alert (data); //that will show (test= TEST pos4)
   }
....
于 2012-07-06T08:31:37.570 回答
0

The reason why your dialig box does not display the posted values, is that you are loading actionclient.php twice - once in your $.ajax call, and then again with $('#editer').load. There's nothing in actionpclient.php that saves anything on the server, thus the values do not show up when you request actionclient.php the second time.

What you seem to want, is to use the values returned by actionclient.php in your first request:

$.ajax({
    type: "GET",
    url: url_final4,
    data: { test: "TEST", test2: pos4},
    success: function(response){
        $('#test_dialog2').html(response);
    }
});
于 2012-07-06T08:49:02.693 回答
0

succes 函数应该是这样的:

success:function(html){ 
    alert("AJAX response :"+html);
}

实际上,您只是显示与之前发送的相同参数。

于 2012-07-06T08:32:32.507 回答