我很流利使用HTML,主要是PHP。在字段中輸入時檢查用戶名?
我可以用PHP做掃描部分..我只是不確定如何用JavaScript調用PHP函數,因爲我不知道JavaScript。
我的PHP代碼將連接到我的MySQL數據庫,看看目前在文本框中的文本(不點擊進入呢,還是打字)是在數據庫..
你知道如何做到這一點,或至少知道一個鏈接,告訴你如何做到這一點?
我很流利使用HTML,主要是PHP。在字段中輸入時檢查用戶名?
我可以用PHP做掃描部分..我只是不確定如何用JavaScript調用PHP函數,因爲我不知道JavaScript。
我的PHP代碼將連接到我的MySQL數據庫,看看目前在文本框中的文本(不點擊進入呢,還是打字)是在數據庫..
你知道如何做到這一點,或至少知道一個鏈接,告訴你如何做到這一點?
這post具有您可以將您的代碼適應
這聽起來像jQuery的一個問題一個很好的例子。我會給你一個冗長的例子,但有很多人會給你一個更好的:like this guy。
考慮使用jQuery與jQuery UI,特別是autocomplete。我相當確定它是做你想做的,而且它對你的網站來說是完全可以實現的。
我看到大家都很喜歡jQuery,哇! 我想告訴你只需要一些非常基本的Ajax腳本來調用你的PHP腳本並接收響應。 下面是簡單的JavaScript函數(實際上是兩個):
function getXMLObject() {
var xmlHttp = false;
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");// For Old Microsoft Browsers
}
catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");// For Microsoft IE 6.0+
}
catch (e2) {
xmlHttp = false;// No Browser accepts the XMLHTTP Object then false
}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest();//For Mozilla, Opera Browsers
}
return xmlHttp;// Mandatory Statement returning the ajax object created
}
var xmlhttp = new getXMLObject();//xmlhttp holds the ajax object
//use this method for asynchronous communication
function doRequest(scriptAddressWithParams, callback) {
if (xmlhttp) {
xmlhttp.open("POST", scriptAddressWithParams, true);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
callback(xmlhttp.responseText);
}
else {
alert("Error retrieving information (status = " + xmlhttp.status + ")\n" + response);
}
}
};
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send(null);
}
}
和這裏的用法的例子:
<input type="text" onchange="doRequest('myphpscript.php?checkvalue='+this.value, function (returnedText) { alert(returnedText);});"/>
如果你打算做一個登錄頁面上,我會建議反對出於安全原因。積極地告訴潛在的黑客一部分登錄信息,他們需要訪問別人的訪問權限,通常不是一個好主意。 – 2011-01-18 23:05:18
我建議你學習JavaScript,然後學習jQuery。這是一種簡單而強大的語言。你可能也想看看Ajax,否則,你總會發現困難,實現最簡單的事情。 – 2011-01-19 01:01:24