简体   繁体   English

如何从Post中使用JQuery获取表单发布数据?

[英]How can you get form post data with JQuery from the Post?

I have a hidden field where the question_id is unique. 我有一个隐藏字段,其中question_id是唯一的。 I am trying to get that hidden field within jquery from the next page so that I can post a message of the form status. 我正在尝试从下一页获取jquery中的该隐藏字段,以便我可以发布表单状态消息。

Then I will put that status in the HTML at the bottom of the form that was submitted. 然后,我将该状态放在提交表单底部的HTML中。

form.php form.php

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery File Upload</title>
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script>

    function submitForm(upload_input_field){
        upload_input_field.form.submit();
        return true;
    }
    $(function () {
    });
  </script>
</head>
<body>
    <form action="uploadFile.php" target="uploadIframe" method="post" enctype="multipart/form-data">
        <input type='button' class='btn btn-default' onClick='submitForm(this)' value='Submit' />
        <input name='question_id' value='123' type='hidden' />
    </form>
    <iframe style="border:0;" id="uploadIframe" name="uploadIframe"></iframe>
    <div id="successMessage123"></div>
</body>
</html>

uploadFile.php uploadFile.php

<?php   $question_id = $_POST['question_id']; ?>
  <script>
    $(document).ready(function(){
         $("[name=question_id]").val(var questionid);
        //alert(question_id);
        //$(('#successMessage_'+question_id), window.parent.document).html('<p>hidden value success</p>');
        $('#successMessage_'+question_id).html('<p>hidden value success</p>');
    });
</script>

Your JavaScript, which is client-side, (JQuery is a JS library) can only parse content rendered/output by the server(PHP). 您的客户端JavaScript(JQuery是一个JS库)只能解析服务器(PHP)呈现/输出的内容。 One easy solution would be inline PHP like this: 一种简单的解决方案是像这样的内联PHP:

<?php   $question_id = $_POST['question_id']; ?>
  <script>
    $(document).ready(function(){
        $("[name=question_id]").val(<?=$question_id?>);
        $('#successMessage_'+question_id).html('<p>hidden value success</p>');
    });
</script>

i think this code will helps you ` 我认为这段代码将帮助您`

<?php   $question_id = $_POST['question_id']; ?>
  <script>
    $(document).ready(function(){
         $("[name=question_id]").val(<?php echo $question_id ?>);

        $('#successMessage_'+<?php echo $question_id ?>).html('<p>hidden value success</p>');
    });
</script>`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM