表单不在jQuery中的load()之后提交

时间:2018-04-19 12:05:00

标签: php jquery ajax post

我有两个页面,main.phpuser_profile.php

我在user_profile.php

中存在的#user_profile_content内加载main.php

以下是user_profile.php

中的一些代码
<table><tbody>
    <tr>
    <th><?php echo $lang['SEND_MESSAGE']; ?></th>
    <td>
      <a href="#send_msg" class="modal-trigger"><i class="material-icons">mail</i></a>
    </td>
    </tr>
</table></tbody>

这将打开一个包含表单

的模态
<div id="send_msg" class="modal">
    <div class="modal-content">
      <span><?php echo $lang['SEND_MSG_TO']." : ".$user_username; ?></span>
      <form id="send_msg_form" method="post">

        <input type="text" name="Message" placeholder="<?php echo $lang['WRITE_MESSAGE']?>" />

    </div>
    <div class="send_modal_footer">
      <button id="submit_msg" class="btn-flat" type="submit">Send</button
  </div>
  </form>
  </div>
  $('#send_msg').modal();

另外php:

  //send msg to user
  if (isset($_POST['Message']))
    {
      $message = mysqli_real_escape_string($connection,$_POST['Message']);
      $query_username_result = mysqli_query($connection,
      "INSERT INTO msg
       SET
       TXT='{$message}',
       FROM_USERNAME='{$username_session}',
       TO_USERNAME='{$user_name}',
       FROM_ID='{$my_id}',
       TO_ID='{$user_id}',
       FROM_ID_STATUS=1,
       ON_DATE='{$now}'");
    }
 ?>

以上代码user_profile.php中的所有代码都将通过此代码加载到main_pm.php中:

var USER_ID = 0;
function UserProfile(user_id)
{
USER_ID = user_id; // now its global variable
              $.ajax({
                  type: "POST",
                  url: "main.php",
                  data: {ID: USER_ID},
                  success: function(msg)
                  {
                    $('#user_profile_content').load('user_profile.php?ID='+USER_ID);
                 },
                  error: function()
                  {
                      alert("error");
                  }
              });
}

user_profile.php?ID=+USER_ID将在此处加载:

 <div class="option_dialog" id="user_profile">
 <div class="close_option">User profile <img onclick="user_profile()" 
 style="float:right;height:20px" src="img/close.png"></div>
 <div id="user_profile_content" style="overflow:scroll;max-height:400px">

 <!--user profile will be loaded here based on returned value -->   

 </div>
 </div>

一切正常,但是最令人困惑的问题,表格在所有这些之后都无法正常工作,但如果我直接从user_profile.php尝试它就可以了。

0 个答案:

没有答案