Yanis Boucherit
Yanis Boucherit

Reputation: 21

Unable to get value (post) with jquery.post

I have a little problem in order to get some values from a page.

I have the following jQuery UI script :

 $(function() {
    $( "#dialog" ).dialog({
        autoOpen: false,
        show: "slideUp",
        hide: "slideDown",
        height: "300",
        width: "400",
        title: "Test pop-up",
        buttons: {
            "Close": function(){
                $(this).dialog("close");
                    }
                }
            }           
        );

    $( "p.diag").click(function(e) {
        var monUrl = 'test2.php';
        $.post("test2.php", { name: "test", time: "test" } );
        $('#dialog').load(monUrl, function(response, status) {
        $('#test_dialog').html(response);
        pos = $("p.diag").attr("id");       
    });
    $( "#dialog" ).dialog("open");      
    e.preventDefault();

});

The test2.php page looks like this :

<?php
$var = $_POST['name'];
echo 'name = '.$var.'';
?>

I just want to retrieve the "name" value from my jQuery Script, but whatever I do, the $_POST['name'] remains void...

Any clue ? Am-I doing something wrong ?

Thanks !

Upvotes: 1

Views: 108

Answers (2)

Krishna
Krishna

Reputation: 353

use this method for take response from php You did wrong

 $.post("test2.php", { name: "test", time: "test" },function(data){
  $('#test_dialog').html(data);  
  });

Upvotes: 3

xdazz
xdazz

Reputation: 160843

You don't have callback handler in your code.

$.post("test2.php", { name: "test", time: "test" }, function(data) {
  console.log(data);
});

Upvotes: 4

Related Questions