简体   繁体   中英

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

I have a hidden field where the question_id is unique. 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.

Then I will put that status in the HTML at the bottom of the form that was submitted.

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

<?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). One easy solution would be inline PHP like this:

<?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>`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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