1

JQueryでWebフォームを開発し、PHPページに投稿して送信しています。

次のようになります。

$('#form-signup').submit(function(e)
{
    $.ajax(
    {
        type: 'POST',
        data: { name: $('#name').val() },
        url: 'signup_backend.php',
        success: function(data, textStatus, jqXHR)
        {
        },
        error: function(jqXHR, textStatus, errorThrown)
        {
            alert('error');
        }
    });

私のWebフォームは次のようになります。

<form id="form-signup" action="">
    <fieldset>
        <label for="name">Nome</label>
        <input type="text" id="name" name="name" value="<?=$name?>"><span class="required">*</span>
    </fieldset>
    <fieldset>
        <label for="email">Email</label>
        <input type="email" id="email" name="email" value="<?=$email?>"><span class="required">*</span>
    </fieldset>
    <fieldset>
        <label for="tel">Telefone</label><input type="tel" id="tel" name="tel" value="<?=$tel?>"><span class="required">*</span>
    </fieldset>
    <fieldset>
        <div>
            <label class="blocker">Tipo de anunciante</label><span class="required">*</span>
        </div>
        <input type="radio" name="advertiser" id="advertiser_1">
        <label for="advertiser_1" class="aleft">Particular</label>
        <input type="radio" name="advertiser" id="advertiser_2">
        <label for="advertiser_2" class="aleft">Imobiliária</label>
    </fieldset>
    <fieldset>
        <label for="password">Senha</label>
        <input type="password" id="password" name="password" value="<?=$password?>"><span class="required">*</span>
    </fieldset>
    <fieldset>
        <label for="check-password">Confirmação da senha</label>
        <input type="password" id="check-password" name="check_password" value="<?=$check_password?>"><span class="required">*</span>
    </fieldset>
    <fieldset>
        <input type="submit" value="Enviar" id="sub">
    </fieldset>
</form>

返品を受け取ると、住所に次のように表示されます。

http://localhost:8888/guia/web/adm/signup.php?name=John&email=&tel=&password=&check_password=

アドレスバーからこれらのデータを回避する方法はありますか?

みんなありがとう

4

5 に答える 5

6

フォーム送信のデフォルトアクションを防止する

$('#form-signup').submit(function(e){
    e.preventDefault(); /// <--- THIS LINE
    $.ajax({
        type: 'POST',
        data: {name: $('#name').val()},
        url: 'signup_backend.php',
        success: function(data, textStatus, jqXHR){

        },
        error: function(jqXHR, textStatus, errorThrown){
            alert('error');
        }
    });
});
于 2012-09-27T14:57:52.183 に答える
2

(submit関数の)ハンドラーの最後でfalseを返そうとしましたか?

于 2012-09-27T14:58:19.997 に答える
1

イベントのデフォルトの動作(フォームの送信)を妨げていないように見えるsubmitため、フォームの送信時にAJAXPOSTリクエストと通常のGETフォームの送信の両方を受け取ります。

これを追加:

e.preventDefault();

イベントハンドラー関数に接続してsubmit、デフォルトのフォーム送信を防ぎ、AJAXPOSTリクエストのみを送信します。

于 2012-09-27T14:58:22.573 に答える
0

タグでを定義できmethod='POST'ますform。これにより、jquery関数内に配置せずに、タイプも指定されます。

<form id="form-signup" action="POST">

以下のように:

<form id="form-signup" action="POST">
    <fieldset>
        <label for="name">Nome</label>
        <input type="text" id="name" name="name" value="<?=$name?>"><span class="required">*</span>
    </fieldset>
    <fieldset>
        <label for="email">Email</label>
        <input type="email" id="email" name="email" value="<?=$email?>"><span class="required">*</span>
    </fieldset>
    <fieldset>
        <label for="tel">Telefone</label><input type="tel" id="tel" name="tel" value="<?=$tel?>"><span class="required">*</span>
    </fieldset>
    <fieldset>
        <div>
            <label class="blocker">Tipo de anunciante</label><span class="required">*</span>
        </div>
        <input type="radio" name="advertiser" id="advertiser_1">
        <label for="advertiser_1" class="aleft">Particular</label>
        <input type="radio" name="advertiser" id="advertiser_2">
        <label for="advertiser_2" class="aleft">Imobiliária</label>
    </fieldset>
    <fieldset>
        <label for="password">Senha</label>
        <input type="password" id="password" name="password" value="<?=$password?>"><span class="required">*</span>
    </fieldset>
    <fieldset>
        <label for="check-password">Confirmação da senha</label>
        <input type="password" id="check-password" name="check_password" value="<?=$check_password?>"><span class="required">*</span>
    </fieldset>
    <fieldset>
        <input type="submit" value="Enviar" id="sub">
    </fieldset>
</form>
于 2017-09-11T12:37:35.677 に答える
0

に依存する別の方法jQuery.ajax([settings])

$.ajax({
    processData : false
)};

URL:http ://api.jquery.com/jQuery.ajax/#jQuery-ajax-settings

于 2018-01-19T22:18:30.057 に答える