ajax jquery 问题
<html><head><title>Ajax</title></head><scripttype="text/javascript">varxmlHttp;functi...
<html>
<head>
<title>Ajax</title>
</head>
<script type="text/javascript">
var xmlHttp;
function ajaxFunction()
{
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("您的浏览器不支持AJAX!");
return false;
}
}
}
var username=document.getElementById("username").value;
xmlHttp.onreadystatechange=ajaxfunc;
xmlHttp.open("GET","time.php?username=" + username + "&aa="+Math.random(),true);
xmlHttp.send(null);
}
function ajaxfunc(){
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200){
var response=xmlHttp.responseText;
if(response!="keyi"){
document.getElementById("tishi").innerHTML="该邮箱已经被注册";
}else{
document.getElementById("tishi").innerHTML="该邮箱可以注册";
}
}
}
}
</script>
<style type="text/css">
ul{text-align:center;}
</style>
<body>
<form name="myForm" method="post">
邮箱: <input type="text" name="username" id="username" onBlur="ajaxFunction();" width=""/>
<span id="tishi" style="color:#FF0000;"></span>
</form>
</body>
</html>
这个代码要怎么改成 jquery 形式得啊`` 展开
<head>
<title>Ajax</title>
</head>
<script type="text/javascript">
var xmlHttp;
function ajaxFunction()
{
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("您的浏览器不支持AJAX!");
return false;
}
}
}
var username=document.getElementById("username").value;
xmlHttp.onreadystatechange=ajaxfunc;
xmlHttp.open("GET","time.php?username=" + username + "&aa="+Math.random(),true);
xmlHttp.send(null);
}
function ajaxfunc(){
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200){
var response=xmlHttp.responseText;
if(response!="keyi"){
document.getElementById("tishi").innerHTML="该邮箱已经被注册";
}else{
document.getElementById("tishi").innerHTML="该邮箱可以注册";
}
}
}
}
</script>
<style type="text/css">
ul{text-align:center;}
</style>
<body>
<form name="myForm" method="post">
邮箱: <input type="text" name="username" id="username" onBlur="ajaxFunction();" width=""/>
<span id="tishi" style="color:#FF0000;"></span>
</form>
</body>
</html>
这个代码要怎么改成 jquery 形式得啊`` 展开
1个回答
展开全部
$(function(){
$('#username').blur(function(){
var username = $(this).val();
$.ajax({
data:{"username ":username,"aa":+Math.random()},
type:"GET",
URL:"time.php",
success:function(msg){
if(msg=="keyi"){
$("#tishi").text("该邮箱已经被注册");
}else{
$("#tishi").text("该邮箱可以注册");
}
},
error:function(){
//错误处理
}
});
});
})
够详细了吧 有良心给加点分啊
$('#username').blur(function(){
var username = $(this).val();
$.ajax({
data:{"username ":username,"aa":+Math.random()},
type:"GET",
URL:"time.php",
success:function(msg){
if(msg=="keyi"){
$("#tishi").text("该邮箱已经被注册");
}else{
$("#tishi").text("该邮箱可以注册");
}
},
error:function(){
//错误处理
}
});
});
})
够详细了吧 有良心给加点分啊
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询