0

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??

1
  • 2
    $.("#div1") should be $("#div1") Commented Jul 24, 2013 at 14:20

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

As an exception, please note that the $.get and $.post shorthand AJAX methods DO use that modified format but you'll notice that there is no selector between the jQuery abbreviation $ and the method post(). The same is also applicable to other shorthands, such as $.each().
Doh!! I should have seen that. I was looking at $.get earlier, and must have left the . in there by mistake. Cheers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.