用jQuery加载的POST表单

时间:2014-07-09 18:42:09

标签: javascript php jquery html

当单击表单中的提交按钮时,我在检查PHP时遇到问题,但是该表单是通过jQuery加载的。所以,我有 if(isset($ _ POST [“submit_content”])),当完成后,使用变量$ content回显“将被发送”,但它什么也没做。< / p>

这是我的index.php

<html>
<head>
<title>INDEX</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<?php
session_start();
$content = "";
if(isset($_SESSION["logged"]))
{
    $con = mysqli_connect("localhost","root","","ntech") or die("Error " . mysqli_error($link));
    $get = mysqli_query($con, "SELECT * FROM users WHERE ses_id='$_SESSION[logged]'");
    $got = mysqli_fetch_array($get);
    $header_account = "Signed in as ".$got[1]." | <a href='?&logout=true'>Logout</a><br/>";
    $access = $got[6];
    if($access >= 2) //moderator - can submit & edit
    {
        $content = "<p id='content'></p><script>$('document').ready(function(){
            $('#content').load('mod_view.html');
            });</script>";
            if(isset($_POST["submit"]))
            {
                if(isset($_POST["mod_view_radio"]))
                {
                    $val = $_POST["mod_view_radio"];
                    if($val == "radio_send")
                    {
                        $content = "<p id='content'></p><script>$('document').ready(function(){
                                $('#content').load('send_content.html');
                            });
                            </script>";
                        if(isset($_POST["submit_content"]))
                        {
                            $content = "will be sent";
                        }
                    }
                    else
                    {
                        $content = "<p id='content'></p><script>$('document').ready(function(){
                                    $('#content').load('see_content.php');
                            });</script>";
                        if(isset($_POST["text"]))
                            echo "LOLED";
                    }
                }
                else
                    echo "nothing set<br/>";
            }
            //else echo "not submitted<br/>";
    }
}
else
    $header_account = "<a href='login.php'>Login</a> | <a href='register.php'>Register</a>";
?>
<body>
<?php echo $header_account.$content; ?>
</body>
</html>

这是send_content.html,它加载了jQ:

<html>
<head>
<style>
h1,h2,h3,h4,h5,h6,p {margin:0;}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<form action="#" id="send_content" method="post">
    <input type="number" placeholder="year" name="year" id="year">
    <input type="number" min="1" max="31" placeholder="day" name="day" id="day">
    <select placeholder="month" id="month" name="month">
        <option>January</option>
        <option>February</option>
        <option>March</option>
        <option>April</option>
        <option>May</option>
        <option>June</option>
        <option>July</option>
        <option>August</option>
        <option>September</option>
        <option>Octomber</option>
        <option>November</option>
        <option>December</option>
    </select><br/>
    <h6>*NOTE: Years below 0 will be considered as years B.C.!</h6><br/>
    <textarea placeholder="Description" style="max-width:350px" name="description" id="description"></textarea><br />
    <input type="submit" name="submit_content" id="submit_content">
</form>
</body>
</html>

我做错了什么?请帮助!

1 个答案:

答案 0 :(得分:0)

从我可以告诉$ content将永远是

"<p id='content'></p><script>$('document').ready(function(){
      $('#content').load('send_content.html');
  });
</script>";   

if($val == "radio_send")是评估为true还是false

由于echo "LOLED"仅在if(isset($_POST["text"]))评估为true时被调用,因此可能只是if($val == "radio_send")返回false并且脚本沿{ {1}}分支。