不是页面重新加载功能不工作的jQuery [英] Not page reload function is not working of jQuery

查看:99
本文介绍了不是页面重新加载功能不工作的jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  $(document).ready(function(){

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

表单提交

 < input class =submitid =submitname =submittype =submitvalue =Submit> 

submit.php

 < div id =content> 
< h2 style =color:#FF0000;>感谢提交< / h2>
< / div>

点击提交按钮后,我仍然不知道它是否加载了页面

解决方案

这将帮助您开始一点。



您需要防止正常形式通过阻止按钮上的默认事件来提交。否则,页面将由于表单提交而重新加载。



您还需要将数据发送到服务器。您可以使用 serialize()

  $( click(function(event){
event.preventDefault();
//收集表单数据
var data = $(this).closest('form')。serialize();
//发送数据并加载新内容
$('#content')。load('content / submit.php' ,data,function(){
// new html now exists can run any code here here
});
});
});


jQuery code to not reload the page:

       $(document).ready(function(){

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

Form submit

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

I don't know still its loading the page after clicking the submit button

解决方案

This will help get you started a bit.

You need to prevent the normal form submit by preventing the default event on your button. Otherwise the page will reload due to form submitting.

You also need to send data to server. You can get all the form data using 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
            });
    });
});

这篇关于不是页面重新加载功能不工作的jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆