简体   繁体   中英

Unable to GET data from ajax (get)

I have a little problem with my code ...

I have a page named "listeclients.php" which have several clients with id's etc. I just made a little button in order to send some data to a page named "actionclient.php", which just has to display the parameters I send to it. The actionclient.php consists in this :

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

(It's just a test page).

And here's my jQuery script :

$( "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();
});

My alert with alert(pos4) works great, and the variables are all correct.

The actionclient.php (url_final4) is well loaded in my dialogbox, but it always just print : "test = "

Any clue ? (I did exactly the same code with a POST method in an another page and it works great... I don't understand.)

Thanks !

to see the sended vars you should do :

....
success: function(data){
   alert (data); //that will show (test= TEST pos4)
   }
....

The succes function should be like this :

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

actually you're just displaying same argument that you send before.

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);
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM