首先讓我描述我的情況:使用jquery framwork for ajax
我正要創建一個表單,其中每個字段都有一個幫助按鈕。現在,如果有人點擊幫助,它會從數據庫中獲取數據並將其顯示在div中。例如
<div class="main">
<div class="form">
<!-- my form code will be here-->
</div>
<div class="help">
<!-- this div will show some data using ajax. I need to make database query using ID of help then show the data here-->
</div>
</div><!--end of main-->
現在我讀了關於w3學校的ajax,我在那裏找到了解決方案。這是:
<script>
function loadXMLDoc(a)
{
var xmlhttp;
var temp = "myname.php?id=" + a;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET",temp,true);
xmlhttp.send();
}
</script>
<h2>AJAX</h2>
<button type="button" onclick="loadXMLDoc('1')">Request 1</button>
<button type="button" onclick="loadXMLDoc('2')">Request 2</button>
<button type="button" onclick="loadXMLDoc('3')">Request 3</button>
<div id="myDiv"></div>
如果我點擊一個按鈕,併發送id作爲參數的作品。做了一些谷歌搜索後,我發現最好是使用jQuery框架的Ajax。現在我沒有在Google上獲得關於此的任何初學者教程。現在
如果上面的代碼是確定在這種情況下,用給我一些鏈接或幫助是如何使JavaScript的數據庫查詢和獲取值並將其設置爲使用Ajax一個div。
如果不使用Ajax的話,請給我一些指導,我怎麼可以使用Ajax用於獲取從數據庫中的值,並顯示在一個特定的div的好方法。請記住,我需要發送幫助ID與我將進行數據庫查詢的功能。
我使用WordPress的框架。