473,395 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to load page into div layer using ajax

anfetienne
424 256MB
hi,

I am using ajax to load external pages into a div layer... my reason for this is when in a certain section of the site the transition is smooth with no white flash.

my problem is that when a page has been loaded into the div layer I have a custom scroll which i use for div box overflow... the scroller is not being included, my div layers all resort back to the generic standard browser scroll bar. how can i load the external .js ile along with the page as it seems that it will load everything but an external js file

this is the code i use to load the pages in a div

Expand|Select|Wrap|Line Numbers
  1. //link
  2. <a href="javascript:void()" onclick="javascript:sendRequest('friends.php', 'connectionsHolder')">Friends</a>
  3.  
  4.  
  5. //ajax code
  6. function createRequestObject() 
  7. {
  8.     var returnObj = false;
  9.  
  10.     if(window.XMLHttpRequest) {
  11.         returnObj = new XMLHttpRequest();
  12.     } else if(window.ActiveXObject) {
  13.         try {
  14.             returnObj = new ActiveXObject("Msxml2.XMLHTTP");
  15.  
  16.             } catch (e) {
  17.             try {
  18.             returnObj = new ActiveXObject("Microsoft.XMLHTTP");
  19.             }
  20.             catch (e) {}
  21.             }
  22.  
  23.     }
  24.     return returnObj;
  25. }
  26.  
  27. var http = createRequestObject();
  28. var target;
  29.  
  30. // This is the function to call, give it the script file you want to run and
  31. // the <strong class="highlight">div</strong> you want it to output to.
  32. function sendRequest(scriptFile, targetElement)
  33. {    
  34.     target = targetElement;
  35.     try{
  36.     http.open('get', scriptFile, true);
  37.     }
  38.     catch (e){
  39.     document.getElementById(target).innerHTML = e;
  40.     return;
  41.     }
  42.     http.onreadystatechange = handleResponse;
  43.     http.send();    
  44. }
  45.  
  46. function handleResponse()
  47. {    
  48.     if(http.readyState == 4) {        
  49.     try{
  50.         var strResponse = http.responseText;
  51.         document.getElementById(target).innerHTML = strResponse;
  52.         } catch (e){
  53.         document.getElementById(target).innerHTML = e;
  54.         }    
  55.     }
  56. }
  57.  
  58.  
  59.  
  60. //this is the page code that i am trying to load
  61. <?php session_start(); ?>
  62. <link href="css/mainCSS.css" rel="stylesheet" type="text/css" />
  63. <link href="css/indexCSS.css" rel="stylesheet" type="text/css" />
  64. <?
  65. include ("admin-dbcon.php");
  66.  
  67. $userName = $_SESSION['_amember_user']['login'];
  68. $firstName = $_SESSION['_amember_user']['name_f'];
  69. $firstName = ucfirst($firstName); 
  70. $lastName = $_SESSION['_amember_user']['name_l'];
  71. $lastName = ucfirst($lastName); 
  72.  
  73. $commentID=rand(0000000000,9999999999);
  74. $dateAdded = gmdate("d M Y H:i:s");
  75. $userAV="user/$userName/av/av.jpg";
  76. $profilePic="user/$userName/profilePic/profile.jpg";
  77. $formLocation="commentsBox";
  78. ?>
  79. <style type="text/css">
  80. <!--
  81. a:link {
  82.     color: #FFFFFF;
  83.     text-decoration: none;
  84. }
  85. a:visited {
  86.     text-decoration: none;
  87.     color: #FFFFFF;
  88. }
  89. a:hover {
  90.     text-decoration: underline;
  91.     color: #E9C100;
  92. }
  93. a:active {
  94.     text-decoration: none;
  95.     color: #FFFFFF;
  96. }
  97. .style5 {
  98.     font-family: Verdana, Arial, Helvetica, sans-serif;
  99.     font-size: 12px;
  100.     font-weight: bold;
  101. }
  102. .style6 {
  103.     font-family: Verdana, Arial, Helvetica, sans-serif;
  104.     font-size: 10px;
  105.     font-weight: bold;
  106.     color: #666666;
  107.     text-align: center;
  108. }
  109. .style7 {
  110.     font-family: Verdana, Arial, Helvetica, sans-serif;
  111.     font-size: 14px;
  112.     font-weight: bold;
  113. }
  114. .style11 {font-size: 10px}
  115. -->
  116. </style>
  117.  
  118. //it won't load this flexcroll.js along with the whole page and reverts the scroll bar back to the standard browser bar
  119. <script type="text/javascript" language="javascript" src="Scripts/flexcroll.js"></script>
  120.  
  121. <div id='connectionsFrameHolder' class='flexcroll'>
  122. <div style="width:300px; height:auto;">
  123. <?
  124. mysql_connect($hostname,$username,$password);
  125. @mysql_select_db($database) or die( "Unable to select database");
  126.  
  127. $sql = "SELECT * FROM friendsList WHERE userName='{$userName}'";
  128. $res = mysql_query( $sql ) or die( mysql_error );
  129.  
  130.     if ( mysql_num_rows( $res ) > 0 ){
  131.     $row = mysql_fetch_array( $res );
  132.  
  133.     $str = $row['friendID'];
  134.     $userID = explode(",",$str);
  135.     $sts = $row['friendAV'];
  136.     $userAV = explode(",",$sts);
  137.     $arrayLength = count($userID);
  138.  
  139.         for($i=0;$i<$arrayLength;$i++)
  140.         {
  141. echo '<div style="width:300px; height:auto; overflow:visible">';  
  142. echo '<table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">';
  143.   echo '<tr>';
  144.     echo '<td width="50" height="50"><img src="Images/noImage.png" height="50" width="50"/></td>';
  145.     echo '<td width="15">&nbsp;</td>';
  146.     echo '<td width="215"><table width="215" border="0" cellspacing="0" cellpadding="0">';
  147.       echo '<tr>';
  148.         echo '<td height="50">'.ucwords($userID[$i]) .'<br />
  149.           location
  150.         </td>';
  151.       echo '</tr>';
  152.     echo '</table></td>';
  153.   echo '</tr>';
  154. echo '</table>';
  155. echo '</div>';
  156.         } 
  157. }
  158. mysql_close();
  159. ?>
  160. </div>
  161. </div>
  162.  
Jun 1 '10 #1
5 3567
acoder
16,027 Expert Mod 8TB
1. Load the script into the page:
Expand|Select|Wrap|Line Numbers
  1. var script = document.createElement("script");
  2. // then set the src and append to the head
2. or use eval
3. or have the script already included in the parent page.
Jun 2 '10 #2
anfetienne
424 256MB
i used a ajax tutorial to get that far with my code lol... could you explain that script in a little more detail or show me a place i can learn it?
Jun 2 '10 #3
acoder
16,027 Expert Mod 8TB
Once you've created a script element, set the source and add it to the head:
Expand|Select|Wrap|Line Numbers
  1. script.src = "file.js";//location of file
  2. document.getElementsByTagName("head")[0].appendChild(script);
Jun 3 '10 #4
anfetienne
424 256MB
just an idea i want to pass by you... since the pages that i am loading are php... wouldn't it be easier to use php to echo the script src into the header on load?
Jun 9 '10 #5
acoder
16,027 Expert Mod 8TB
That'd work for the initial page, but when using Ajax, the PHP page will be loaded separately, so any JavaScript will have to be evaled or added manually.
Jun 21 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Martin | last post by:
Hello NG, I've been doing some AJAX for a few weeks now. The basics worked fine so far, but now I've got the following problem which I can't solve: With AJAX you typically update/replace only...
9
by: preetksaini | last post by:
hi i am having a page in which i have 3 dropdowns,values of 2nd dropdown comes based on 1st and values of 3rd dropdown come based on 2nd.using AJAX+PHP to load dropdowns. but whenever i refresh...
13
by: Marvin Zhang | last post by:
Hi, I'm not familiar with web programming, but I have a problem here. I have a page. When a user click one button on it, I will use AJAX to request a PHP script which will do a bunch of tasks,...
3
by: xhunter | last post by:
I am loading a page using ajax, but the problem is that the javascript functions existing on that page would no longer be available when loaded through ajax, is there anyways to load a page in a...
0
by: ofek | last post by:
Hello, I've been trying, for the last 3 days, to load an ASCX file, using AJAX, unsuccessfully. I do as follows: 1. I have an ASPX page that use a javascript function to call a web page. 2....
2
by: sujathaL | last post by:
Here,i am getting the table from another page by using ajax.i want to get values which are in the table.how to get those values using javascript.
2
by: soms2m | last post by:
hello all, I am a just a beginer in this community also to this topic, i want to load a page using ajax. the parent should not be refreshed also its should have a dim background color which one i...
3
by: ton | last post by:
Hi, I'm using AJAXPRO this works very well. What I want to do is to add new page elements at my web site without using a postback. And I do not mean listitems but a complete dialog. Let me...
0
by: Abubakar | last post by:
Hi, I've been assigned to work on a asp.net page that when viewed on internet, renders very slowly and its hosted on a client machine which is a p4 3.0ghz HT, with 2 gb ram running windows...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.