【发布时间】:2023-03-16 16:47:02
【问题描述】:
我想使用 jQuery 将此文本字段值发送到 php 文件。
HTML 代码:
<div>
<label for="email">Email: </label>
<input type="text" id="email" name="email" />
<span id="msgbox" class="msgbox"></span>
</div>
jQuery 代码:
$(document).ready(function()
{
$("#email").blur(function()
{
$("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");
$.post("availability.php", { email: $(this).val() }, function(data)
{
if(data == 'yes')
{
$("#msgbox").fadeTo(200, 0.1, function()
{
$(this).html('Email Already exists').addClass('messageboxerror').fadeTo(900,1);
});
}
else
{
$("#msgbox").fadeTo(200, 0.1, function()
{
$(this).html('Email available to register').addClass('messageboxok').fadeTo(900,1);
});
}
});
});
});
PHP 代码:
include_once $_SERVER['DOCUMENT_ROOT'] . '/braddclient/includes/magicquotes.inc.php';
include $_SERVER['DOCUMENT_ROOT'] . '/braddclient/includes/db.inc.php';
$email = mysqli_real_escape_string($link, $_POST['email']);
$sql = "SELECT * FROM bradduser WHERE email='$email'";
$result = mysqli_query($link, $sql);
if(!$result)
{
$error = 'Error fetching email from bradduser.';
include 'error.html.php';
exit();
}
if(mysqli_num_rows($result) > 0)
{
echo ‘yes’; //email already exist
}
else
{
echo ‘no’;
}
代码的问题在于,这似乎不是 jquery 和 php 之间的通信。数据拒绝发送到 php。请帮忙看看代码有什么问题。
【问题讨论】:
-
至少尝试很好地格式化您的代码...