为了自动化这个过程,我还编写了一个js脚本,它自动向PHP脚本发送AJAX调用,并告诉用户域是否可用,而无需提交表单:
$(document).ready(function() {
function Domain() {
this.name = '';
this.dotComRegistered = 1;
this.dotNetRegistered = 1;
this.dotOrgRegistered = 1;
}
Domain.prototype.check = function(input) {
this.name = input;
if (this.name.length >= 3 && this.name.length <= 63) {
$.get('check.php', { d : this.name }, function(json) {
alert(json);
this.dotComRegistered = $.evalJSON(json).com;
this.dotNetRegistered = $.evalJSON(json).net;
this.dotOrgRegistered = $.evalJSON(json).org;
});
}
}
var domain = new Domain();
var input = ''
$('#domain').keyup(function() {
input = $('#domain').val();
domain.check(input);
});
$('form').submit(function() {
input = $('#domain').val();
domain.check(input);
return false;
});
});
问题是Domain.prototype.check()方法不起作用(我没有收到警报窗口),我不知道问题出在哪里。当我将AJAX调用放在方法之外时,它是有效的,所以这不是问题所在。
#域是域名的输入字段。