IGGt
IGGt

Reputation: 2779

JQuery .load passing PHP variables

what am I missing please. I am looking at replacing my ageing AJAX queries, with jQuery equivalents. But have become stumped at the point where I pass the PHP variables across.

I have the following test page:

##PAGE1.php##
<?php
$var1 = "hello";
$var2 = "again";
?>
<html>
    <head>
    <script language="JavaScript" src="../Generic/JAVASCRIPT/jquery.js" type="text/javascript"></script>
    <script>
    $(document).ready(function()
        {
            $("button").click(function()
                {
                    $.("#div1").load("page2.php?var1=<?php print $var1;?>&var2=<?php print $var2;?>");
                }
            );
        }
    );

    </script>
    </head>
    <body>

    <div id="div1">
        <h2>This is where it should happen</h2>
    </div>

    <button>Click Me</button>

</body>
</html>

##PAGE2.php##
<?php
$v1 = $_GET['var1'];
$v2 = $_GET['var2'];
print $var1 . " & " . $var2;
?>  

But When I run this (testing in Chrome) I get:

Uncaught SyntaxError: Unexpected token ( 
page1.php:9

which apparently relates to the main line of jQuery ($."#div1").load . . . .

But all the () look fine to me???

Can someone spot my mistake??

Upvotes: 0

Views: 1086

Answers (1)

Brian
Brian

Reputation: 7654

jQuery selectors are called with $("#div1").load( instead of $.("#div1").load(. Note the extra period.

Upvotes: 3

Related Questions