【问题标题】:Not page reload function is not working of jQuery [closed]非页面重新加载功能不适用于 jQuery [关闭]
【发布时间】:2016-01-25 22:36:23
【问题描述】:

不重新加载页面的jQuery代码:

       $(document).ready(function(){

         $('#submit').click(function(){
        var page = $(this).attr('id');
        $('#content').load('content/submit.php');
          });
     });

表单提交

<input class="submit" id="submit" name="submit" type="submit" value="Submit">

submit.php:

<div id="content">
   <h2 style="color:#FF0000;"> Thanks For the Submission </h2> 
</div>

我不知道点击提交按钮后它是否还在加载页面

【问题讨论】:

    标签: javascript php jquery html reload


    【解决方案1】:

    这将帮助您入门。

    您需要通过阻止按钮上的默认事件来阻止正常的表单提交。否则页面会因为表单提交而重新加载。

    您还需要向服务器发送数据。您可以使用serialize()获取所有表单数据

    $(function(){
        $('#submit').click(function(event){
               event.preventDefault();
               // collect the form data
               var data = $(this).closest('form').serialize();
                // send the data and load new content
                $('#content').load('content/submit.php', data, function(){
                     // new html now exists can run any code needed here
                });
        });
    });
    

    【讨论】:

    • 我如何将默认事件放在我的提交按钮上??
    • 我已经用event.preventDefault() 做到了。这将停止触发表单提交的按钮
    • 好的,让我检查一下
    • 现在提交按钮不起作用
    • 什么也没发生
    猜你喜欢
    • 1970-01-01
    • 2017-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多