user1506157
user1506157

Reputation: 115

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 !

Upvotes: 0

Views: 87

Answers (3)

Vidar S. Ramdal
Vidar S. Ramdal

Reputation: 1242

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

Upvotes: 0

Damien Locque
Damien Locque

Reputation: 1809

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.

Upvotes: 0

mgraph
mgraph

Reputation: 15338

to see the sended vars you should do :

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

Upvotes: 4

Related Questions