felito Posted October 30, 2011 Share Posted October 30, 2011 hi i have this code: $something ="text"; <script type="text/javascript"> $(document).ready(function() { $("#custom").submit(function() { var formdata = $("#custom").serialize(); $.ajax({ url: "dojo/insert.php", type: "post", dataType: "json", data: formdata, success: function(data) { switch (data.livre) { case 'valorLivre': $("#msg").fadeTo(200, 0.1, function() { $(this).html('Deve fazer a ponderação de competências!').fadeTo(900, 1); }); break; default: $("#msg").fadeTo(200, 0.1, function() { $(this).html('Oferta colocada!').fadeTo(900, 1); $.ajax({ url: "oferta.php", type: "post", dataType: "json", data:{ name:<?php echo $something; ?> //problem here }, success: function(data) { $('#total').load('oferta.php'); } }); }); break; } } }); return false; }); }); </script> when i run the page i get text is undefined. What is wrong in this code ? thanks Quote Link to comment https://forums.phpfreaks.com/topic/250083-pass-php-variable-value-to-jquery-function/ Share on other sites More sharing options...
AyKay47 Posted October 30, 2011 Share Posted October 30, 2011 I find that passing a PHP variable to a jquery function via an argument seems to be the best method.. $something = "text"; <form onsubmit='handleForm("<?php echo $something; ?>");'> then grab it like this.. function handleForm(something){ document.write(something); } Quote Link to comment https://forums.phpfreaks.com/topic/250083-pass-php-variable-value-to-jquery-function/#findComment-1283375 Share on other sites More sharing options...
felito Posted October 30, 2011 Author Share Posted October 30, 2011 thanks Quote Link to comment https://forums.phpfreaks.com/topic/250083-pass-php-variable-value-to-jquery-function/#findComment-1283376 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.