誰もがjQueryを好きなので、うわー! PHPスクリプトを呼び出してレスポンスを受け取るためには、非常に基本的なAjaxスクリプトが必要なことを伝えたいと思います。 ここでは、簡単なJavaScriptの機能(実際は2)です:
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);});"/>
あなたはログインページにこれを実行しようとしている場合、私はそれに対してお勧めしますセキュリティ上の理由から。他のユーザーのアクセスにアクセスするために必要なログイン情報を積極的に潜在的なハッカーに伝えることは、通常はお勧めできません。 –
JavaScriptとjQueryを学ぶことをお勧めします。シンプルでパワフルな言葉です。また、Ajaxを見たいと思うかもしれません。そうでなければ、最も簡単なことを実装して、常に困難を見つけるでしょう。 –