Greg
Greg

Reputation: 1055

Passing PHP variables to a jQuery Modal window

Hey Guys, I am new to jQuery and am not experienced with it at all...

Basically my goal is to have a modal popup with php variables passed to it...

for example - EITHER load a popup php page, view_details.php?id=1

OR

pass the php variables directly to the modal for the specified id.

I hope my question is not too confusing and is understandable, any advice would be recommended. I currently have jqueryUI installed, but am open to using any module.

Greg

Upvotes: 1

Views: 4968

Answers (3)

Naftali
Naftali

Reputation: 146350

Ok so:

$('<div>').load('something.php').dialog();

And voila you have your dialog :-)

Upvotes: 3

Dutchie432
Dutchie432

Reputation: 29170

$('#modalDivID').load('view_details.php?id=1').dialog();

view_details.php

<?php
    $id=$_REQUEST['id'];
    echo 'This is popup #'.$id;
?>

Upvotes: 1

Mikk
Mikk

Reputation: 2229

You might also want check out json datatype so youcould iterate over list of variables.

    $.ajax({
        url: 'request.php',
        data: {'getParam1': 'foo', 'getParam2': 'bar'},
        dataType: 'json',
            success: function(response) {
                $div = $('#myDiv'); //Id for your div
                    $.each(response, function(k, v) {
                        $div.append(v);
                    }); 
                $div.dialog();
            }
    });

request.php

<?php

    $variables = array(
        'variable1',
        'variable2',
        'variable3',
        'param1: '.$_GET['getParam1'],
        'param2: '.$_GET['getParam2']
    );

echo json_encode($variables);

?>

Upvotes: 1

Related Questions