Iladarsda
Iladarsda

Reputation: 10696

jQuery .get - how to display the result of the .get request?

I'm TRYING to get jQuery .get to work.

I have two files.

I. Where I'm perfoming this, on .click event:

         $.get("employee.php", 
            { FirstName: substr[0], LastName: substr[1] }, 
            function(data) {

                // HOW DO DISPLAY THE RESPONSE in #div?

            }
        );

substr coming from: var substr = ( $(this).html() ).split('<span>')[0].split(' ');

II. Params are being successfuly past to employee.php and firebug display the response like this:

<div class="employeePopUpBox">

    GET isn't empty. John, Doe

</div>

PHP file:

<div class="employeePopUpBox">

    <?php
    if(!empty($_GET)) {
        $FistName = $_GET['FirstName'];
        $LastName = $_GET['LastName'];
        echo 'GET isn\'t empty. '.$FistName.', '.$LastName;
    } else {
        echo "GET is empty";
    }
?>

The quastion is how to display the response inside div#response?
Any suggestion are much appreciated.

Upvotes: 0

Views: 2293

Answers (1)

genesis
genesis

Reputation: 50976

Just use normal .html() method.

 $.get("employee.php", 
    { FirstName: substr[0], LastName: substr[1] }, 
    function(data) {
       $("div#response").html(data);
    }
);

or use this one, one-line instead

 $("div#response").load("employee.php?FirstName="+substr[0]+"&LastName="+substr[1]);

Upvotes: 4

Related Questions