我需要帮助提交表单。我不想页面刷新,我不知道如何做到这一点 [英] I need help submitting a form. I do not want the page to refresh, and I do not know how to accomplish this

查看:192
本文介绍了我需要帮助提交表单。我不想页面刷新,我不知道如何做到这一点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用一个按钮提交表单,而不是一个提交按钮。不过,我的问题是,我当我preSS进,形式不不会提交,所以不是我实际上是点击提交按钮,它可以是不方便。我想知道我怎么可以用一个按钮从提交我而无需刷新页面,当我preSS进入,也有形式提交。我觉得这是一个非常简单的解决方法,我只是找不到。这里是URL以在其上发生问题的页面。 http://www.pearlsquirrel.com/register.php

I am using a button to submit a form, not a submit button. However, my problem is that I when I press enter, the form does not not submit, so instead i actually have to click the submit button, which can be inconvenient. I am wondering how I can use a button the submit my from without having the page refresh and when I press enter, also have the form submit. I feel like it is a very easy fix that I just can not find. Here is the URL to the page on which the problem is occurring. http://www.pearlsquirrel.com/register.php

下面是code到register.php

Here is the code to register.php

<div id="centered3">
<h1><div align='center' style="color:white;">Join PearlSquirrel</align></h1>
<h4><div id='response'></div></h4>
<script language='javascript' type='text/javascript'>
function ajaxregister(){
var ajaxRequest;  

try{
    // Opera 8.0+, Firefox, Safari
    ajaxRequest = new XMLHttpRequest();
} catch (e){
    // Internet Explorer Browsers
    try{
        ajaxRequest = new ActiveXObject('Msxml2.XMLHTTP');
    } catch (e) {
        try{
            ajaxRequest = new ActiveXObject('Microsoft.XMLHTTP');
        } catch (e){
            // Something went wrong
            alert('Your browser broke!');
            return false;
        }
    }
}
ajaxRequest.onreadystatechange = function(){
    if(ajaxRequest.readyState == 4){
        var ajaxDisplay = document.getElementById('response');
        ajaxDisplay.innerHTML = ajaxRequest.responseText;

    }
}
var username = document.getElementById('username').value;
var password = document.getElementById('password').value;
var repeatpassword = document.getElementById('repeatpassword').value;
var queryString = '?username=' + username + '&password=' + password +     '&repeatpassword=' + repeatpassword;
ajaxRequest.open('GET', 'ajaxregister.php' + queryString, true);
ajaxRequest.send(null); 

}
</script>
<form method='GET'>
<table>

        <tr>

            <td>
                Choose a username:

            </td>

            <td>
                <script type="text/javascript"     src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
<script>
$(document).ready(function(){
$('#username').keyup(username_check);
});

function username_check(){  
var username = $('#username').val();
if(username == "" || username.length < 4){
$('#username').css('border', '3px #CCC solid');
$('#tick').hide();
}else{

jQuery.ajax({
type: "POST",
url: "check.php",
data: 'username='+ username,
cache: false,
success: function(response){
if(response == 1){
$('#username').css('border', '3px #C33 solid'); 
$('#tick').hide();
$('#cross').fadeIn();
}else{
$('#username').css('border', '3px #090 solid');
$('#cross').hide();
$('#tick').fadeIn();
}

}
});
}

}

</script>
</head>
<script>
function nospaces(evt)
{
 var charCode = (evt.which) ? evt.which : event.keyCode
 if (charCode == 32)
    return false;
 return true;
}
</script><body>

<input name="username" id="username" type="text" style="height:30px; width:212px;"     value='<?php echo $username; ?>' onkeypress="return nospaces(event)"/>
<img id="tick" src="tick.png" width="16" height="16"/>
<img id="cross" src="cross.png" width="16" height="16"/>

</body>
</html>
            </td>

        </tr>

        <tr>

            <td>
                Choose a password:

            </td>

            <td>
                <input type='password' name='password' id='password' style="height:   30px; width:220px;" > 
            </td>

        </tr>

        <tr>

            <td>
                Repeat your password:

            </td>

            <td>
                <input type='password' name='repeatpassword' id='repeatpassword' style="height: 30px; width:220px;" > 
            </td>

        </tr>
        <tr>

            <td>

            </td>

             <td>
                By registering, you agree to the<br><a href="termsofservice.php">terms   of service</a> & <a href="privacypolicy.php">privacy policy</a>
            </td>

        </tr>
        <tr>

            <td>

            </td>

            <td>

<input type='button' name='submit' value='Register' class='registerbutton'    onclick='ajaxregister()'>
<div id="msg"></div> 

            </td>

        </tr>
</table>

    <p>

有code为页面的一部分块。任何帮助将大大AP preciated。谢谢!

There is the block of code for that part of the page. Any help would be greatly appreciated. Thanks!

推荐答案

您得添加安其preSS处理程序输入字段,检查重点code:如果是13(回车),执行Submit按钮处理程序

You gotta add onKeyPress handlers for input fields and check the keyCode: if it is 13 (Enter), execute Submit button handler.

这篇关于我需要帮助提交表单。我不想页面刷新,我不知道如何做到这一点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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