السلام عليكم ورحمة الله وبركاته
هذا كود جميل أستخدمه في أغلب مواقعي في الأجاكس ويتيح لك عمل فتح واغلاق للصفحة بنفس الزر , اللنك أو الصورة حسب طلبات صفحتك .
كود:
var xmlhttp = false;
//Check if we are using IE.
try {
//If the javascript version is greater than 5.
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
//If not, then use the older active x object.
try {
//If we are using IE.
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
//Else we must be using a non-IE browser.
xmlhttp = false;
}
}
//If we are using a non-IE browser, create a JavaScript instance of the object.
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
xmlhttp = new XMLHttpRequest();
}
//starting show function code
show=true;
function show_function()
{
if(show==true)
{
document.getElementById("img_id").src="../images/back.gif";//if you want make the buuton is img
document.getElementById("add1").alt="Back";
var server_page="page_name.php";
xmlhttp.open("GET",server_page);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("div_id").innerHTML = xmlhttp.responseText;
show= false;
}
}
xmlhttp.send(null);
}
else {
//Hide the class.
document.getElementById("img_id").src = "../images/add.gif";
document.getElementById("img_id").alt="Show page";
show= true;
document.getElementById("div_id").innerHTML = "";
}
}
أتمنى أن تكون وفقت في حل مشكلتك بشكل صحيح
مع أطيب التحية