0

Possible Duplicate:
passing variables from php to javascript

I am using this awesome jQuery Stick Notification Plugin which creates notifications upon clicking various buttons. I used the following code to display the notification box...

$(".notify").click(function() {
     $.sticky('The page has loaded!');
});

Can i make it display some PHP variables in place of static text message?

Hope i've made it clear enough.

4
  • you mean to say let it communicate with your php? in other words ajax? Commented Jul 23, 2012 at 8:07
  • no, i was so dumb to not figuring out the simplest method :( nevermind.. its solved :) Commented Jul 23, 2012 at 8:10
  • kindly share how did you solve it. Commented Jul 23, 2012 at 8:12
  • stackoverflow.com/search?q=passing+php+variables+to+javascript Commented Jul 23, 2012 at 8:12

2 Answers 2

4

Without making asynchronous HTTP calls, you will have to insert the PHP variable at server-side:

$(".notify").click(function() {
    $.sticky('<?php echo htmlentities($message); ?>');
});

Wrap it with htmlentities() just in case $message contains some chars that make the JavaScript string invalid.

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

2 Comments

some chars such as a single quote ' ???
Yup, or linebreaks, or some other chars.
1

yes you can like

$(".notify").click(function() {    
 $.sticky('<?php echo "The page has been loaded"; ?>');    
});

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.