php - $_POST with javascript – it works in javascript but not in jquery plugin -
i have form gets submitted. retrieve submitted data javascript on next page.
this works fine when put in body of html:
<script> var $_post = <?php echo json_encode($_post); ?>; document.write($_post["form_input_name"]); </script>
now want have functionality in jquery plugin method. tried following in jquery plugin:
$.pluginname.test = function() { var $_post = <?php echo json_encode($_post); ?>; document.write($_post["form_input_name"]); };
but when try execute in body of html, following error messages:
[error] syntaxerror: unexpected token '<'
[error] typeerror: undefined not object (evaluating '$.pluginname.test')
why code-snipped working in regular javascript environment not when called jquery plugin?
your php tags being evaluated javascript. means php not processing them.
presumably, because have moved script .js
file.
while possible generate javascript file php, won't here: data trying generate being submitted php script generates html document.
move script between <script>
, </script>
in php file generates html.
Comments
Post a Comment