首页
\
问答
\
如何从PHP / AJAX / jQuery中的表单外的JavaScript变量中保存数据?(How to save data from a JavaScript variable outside the form in PHP/AJAX/jQuery?)
如何从PHP / AJAX / jQuery中的表单外的JavaScript变量中保存数据?(How to save data from a JavaScript variable outside the form in PHP/AJAX/jQuery?)
PHP新手在这里。 我想在PHP / MySQL中保存一个变量(来自jQuery),但是这个变量在表单之外。 表格中的表单元素的值虽然保存得很好。 在这种情况下,变量名称是'mode',我希望'mode'被发送到PHP。
这是代码:
HTML表单;
<form action="submit.php" method="post" id="myform"> <textarea id="source1" name="source1"></textarea> <textarea id="source2" name="source2"></textarea> <input type="image" src="images/save.png" name="submit" id="submit" title="Save" class="save-button"/> </form>
jQuery / AJAX:
mode = 1; // This value needs to be stored/saved // AJAX form save $("form#myform").submit( function () { $.post( 'submit.php', $(this).serialize(), function(data){ .... } );
PHP:
$submit_time = date('Y/m/d H:i:s'); $content1 = $_POST['source1']; $content2 = $_POST['source2']; $mode = $_POST['mode']; // This value needs to be stored/saved
是否在表单内创建隐藏表单字段的解决方案?
PHP newbie here. I want to save a variable (from jQuery) in PHP/MySQL, but this variable is outside the form. The values from the form elements inside the form is being saved fine though. The variable name in this case is 'mode', and I want the 'mode' to be sent to PHP.
Here's code :
HTML form;
<form action="submit.php" method="post" id="myform"> <textarea id="source1" name="source1"></textarea> <textarea id="source2" name="source2"></textarea> <input type="image" src="images/save.png" name="submit" id="submit" title="Save" class="save-button"/> </form>
jQuery / AJAX:
mode = 1; // This value needs to be stored/saved // AJAX form save $("form#myform").submit( function () { $.post( 'submit.php', $(this).serialize(), function(data){ .... } );
PHP:
$submit_time = date('Y/m/d H:i:s'); $content1 = $_POST['source1']; $content2 = $_POST['source2']; $mode = $_POST['mode']; // This value needs to be stored/saved
Is the solution to create a hidden form field inside the form?
原文:https://stackoverflow.com/questions/20167997
更新时间:2022-12-14 20:12