gpt4 book ai didi

JQuery post 在地址栏中返回查询字符串

转载 作者:行者123 更新时间:2023-12-01 06:19:54 25 4
gpt4 key购买 nike

我正在 JQuery 中开发一个 Web 表单,并通过 post 发送到 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');
}
});

我的网络表单如下所示:

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

有办法避免这些数据出现在我的地址栏中吗?

谢谢大家

最佳答案

防止表单提交的默认操作

$('#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');
}
});
});

关于JQuery post 在地址栏中返回查询字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12624230/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com