Jump to content

Recommended Posts

Hello. I am trying to build a website with many ajax features.

 

To make the web look more like an app, I am retrieving information with ajax. So i have this code where i can retrieve two different pages with two clicks, but when i retrieve one, and another one on top - i want the first to disappear. However both pages are being loaded. Is there any jQuery method that could effectively hide the first loaded page.

 

These are two functions that can load pages.

// first function to load military.php
function loadMilitary()
{
var xmlhttp2;
if (window.XMLHttpRequest)
{
xmlhttp2 = new XMLHttpRequest;
}

xmlhttp2.onreadystatechange = function()
{
if (xmlhttp2.readyState == 4 && xmlhttp2.status == 200)
{
document.getElementById("military_tab").innerHTML=xmlhttp2.responseText;
}
}
xmlhttp2.open("GET","military.php",true);
xmlhttp2.send();
}


// second function to load hospital.php
function loadHospital()
{
var xmlhttp2;
if (window.XMLHttpRequest)
{
xmlhttp2 = new XMLHttpRequest;
}

xmlhttp2.onreadystatechange = function()
{
if (xmlhttp2.readyState == 4 && xmlhttp2.status == 200)
{
document.getElementById("hospital_tab").innerHTML=xmlhttp2.responseText;
}
}
xmlhttp2.open("GET","hospital.php",true);
xmlhttp2.send();
}

 

And i load them by using the onclick method


<div class="hospital_tab" onclick="loadHospital()"></div>
<div class="military_tab" onclick="loadMilitary()"></div>

 

I really need help with this guys, thanks for any hint! Hope you understood what i want.

Edited by Pain
Link to comment
https://forums.phpfreaks.com/topic/271048-ajax-problem/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.