weixin_33735676 2015-10-22 07:46 采纳率: 0%
浏览 6

Ajax表单显示消息

i have a form that insert in dbase what i write here is the form,

        <form  id="contact-form" class="bl_form text-center" action="<?php echo "index.php?page=rooms&room=$rid&amp;rpw=$rpw&amp;r=$r"; 

?>" method="post" novalidate>
                    <span class="field-wrap scrollimation fade-right">

                        <input type="hidden" id="contact-name" name="contactName" type="text" 

class="label_better requiredField" data-new-placeholder="Name" placeholder="Name" value="<?php echo "$uid"; ?>" data-error-

empty="*Enter your name">
                    </span>
                                        <span class="field-wrap scrollimation fade-left">
                        <label class="control-label" for="contact-message">Message</label>
                        <textarea id="contact-message" name="message" rows="1" class="label_better 

requiredField" data-new-placeholder="Message" placeholder="Message" data-error-empty="*Enter your message"></textarea>
                    </span>

                    <p class="text-center"><button  name="sy2" id="submit_post" type="submit" class="btn btn-meflat 

icon-left" data-error-message="Error!" data-sending-message="Sending..." data-ok-message="Message Sent"><i class="fa fa-paper-

plane"></i>Send Message</button></p>
                    <input type="hidden" name="submitted" id="submitted" value="true" />
                    <?php echo "<postfield name=\"message\" value=\"$(message)\"/>"; ?>
                </form>

and i want to put a ajax code that display this message from dbase

<?php echo make_clickable($tosay)."$link_delete"; ?>

Can someone provide me an example?Thank you

  • 写回答

1条回答 默认 最新

  • 普通网友 2015-10-22 07:48
    关注

    Look at this
    Ajax tutorial for post and get

    So, the jQuery

    $('body').on('submit', '#contact-form', function(){
      $.post({$(this).attr("action"), $(this).serialize(), function(data){
        if(data){
          alert(data.message);
        }
      }, 'json');
      return false;
    });
    

    And the server side

    <?php 
      if($_SERVER['REQUEST_METHOD'] === 'POST'){
        // do your thing here
        echo json_encode(array("message" => make_clickable($tosay).$link_delete));
        die();
      }
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)