passing parameters in ajax through php echo command

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: May 2008
Posts: 74
Reputation: servis is an unknown quantity at this point 
Solved Threads: 0
servis servis is offline Offline
Junior Poster in Training

passing parameters in ajax through php echo command

 
0
  #1
Jun 22nd, 2009
hi,

i have passed following parameters in ajax function,

onclick = "agU(<?php echo $u . ' , ' . $msg; ?>);"
its not working. when i test the same function in following way it runs fine.

onclick = "agU(<?php echo $u; ?>);"
am i commiting any mistake in supplying variable???
please help..
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 959
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 126
ardav's Avatar
ardav ardav is offline Offline
Posting Shark

Re: passing parameters in ajax through php echo command

 
0
  #2
Jun 22nd, 2009
Originally Posted by servis View Post
hi,

i have passed following parameters in ajax function,

onclick = "agU(<?php echo $u . ' , ' . $msg; ?>);"
its not working. when i test the same function in following way it runs fine.

onclick = "agU(<?php echo $u; ?>);"
am i commiting any mistake in supplying variable???
please help..
You need to 'quote' your vars:

onclick = "agU('<?=$u;?>','<?=$msg;?>');"
I've used 'short tags' above - which is frowned upon [PLEEZE no more self-righteous 'I disagrees'!! IDGAD], but you can swap these for the full <?php echo $u;?> and <?php echo $msg;?> if you want.

You could also build a complete parameter string in pHp first (including quote marks) and then just include the php string - without encompassing quote marks.

From what I can see, your problem was quote marks - or should I say, the lack of them.
"...the woods would be a very silent place if no birds sang except for the best"
All opinions count.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC