点击submit按钮,执行ajax,验证输入的用户名是否被占用。这个该怎么实现?

点击submit按钮,执行ajax,验证输入的用户名是否被占用。这个该怎么实现?


不负相思意
浏览 482回答 1
1回答

慕虎7371278

123456789101112131415161718192021222324252627282930313233$(function (){    $("#submit").click(function (){        var username=$("#username").val()        $.ajax({            type: "get",            url:"post.asp",            async: true,            timeout: 15000,            data:{username:username},            beforeSend: function(xhr) {   //beforeSend定义全局变量                xhr.setRequestHeader("If-Modified-Since", "0");  //If-Modified-Since HTTP请求头标签,即比较浏览器缓存页面时间            },            success: function(xmlDoc, textStatus, xhr)             {                if(xhr.readyState==4)                    {                    if(xhr.status == 200)                    {                        var str=xhr.responseText; //获取返回值                        if (str==0){ //查询返回0表示已注册                            alert("已被注册")                            return;                            }                        else{                            //运行正确的代码                            alert("可以正常注册")                            }                    }                }            },        });                    });    });
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JQuery