473,707 Members | 2,285 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

AJAX loading external page into div, no javascript

12 New Member
I have been trying to fix this issue the whole of today and have gotten no where.
I am developing a new website, and wanted it to display a webpage in lightbox and have an external page added to the main page, both worked successfully apart, but it wasn't until I combined them that I have had an issue.

My aim was to have ajax add the external page into a div and then load lightbox from that div, though that is where the problem lies as I can not run any form of javascript from it


--My AJAX Code (from dynamicdrive)
Expand|Select|Wrap|Line Numbers
  1. var loadedobjects=""
  2. function LoadPage(url, containerid){
  3. var page_request = false
  4. if (window.XMLHttpRequest) // if Mozilla, Safari etc
  5. page_request = new XMLHttpRequest()
  6. else if (window.ActiveXObject){ // if IE
  7. try {
  8. page_request = new ActiveXObject("Msxml2.XMLHTTP")
  9. catch (e){
  10. try{
  11. page_request = new ActiveXObject("Microsoft.XMLHTTP")
  12. }
  13. catch (e){}
  14. }
  15. }
  16. else
  17. return false
  18. page_request.onreadystatechange=function(){
  19. loadpage(page_request, containerid)
  20. }
  21. page_request.open('GET', url, true)
  22. page_request.send(null)
  23. }
  24.  
  25. function loadpage(page_request, containerid){
  26. if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
  27. document.getElementById(containerid).innerHTML=page_request.responseText
  28. }
I have tried eval, and many other methods but with no luck, but I am new to ajax / javascript in general so knowing me have probably done stupidly wrong, or missed something very easy which will fix it
Jul 26 '09 #1
29 24404
gits
5,390 Recognized Expert Moderator Expert
so your responseText will contain javascript-code? this code has to be evaled explicitly. you may separate it from the page and include script-tags dynamically or you need to extract the javascript-code from the response and eval it.

kind regards
Aug 1 '09 #2
sukil
3 New Member
Did you get a solution? I have the same issue but cant find the solution!
Aug 3 '09 #3
FreshRob
12 New Member
No am still looking, and trying to find ways around it, though nothing has come up
Aug 3 '09 #4
gits
5,390 Recognized Expert Moderator Expert
did you try to load the script seperately or have it already loaded, so that you just need to call it? you just have to ensure that the script is evaled ... because loading scripts with an XMLHttpRequest will not do that ...
Aug 4 '09 #5
FreshRob
12 New Member
I have an index.php containing:
Expand|Select|Wrap|Line Numbers
  1. <title>index page</title>
  2. <!-- CSS !-->
  3. <link rel="stylesheet" href="css/lightbox.css" media="screen,projection" type="text/css" />
  4. <link rel="stylesheet" href="css/website.css" media="screen,projection" type="text/css" />
  5.  
  6. <!-- JavaScript !-->
  7. <script type="text/javascript" src="scripts/java.js"></script>
  8. <script type="text/javascript" src="scripts/prototype.js"></script>
  9. <script type="text/javascript" src="scripts/lightbox.js"></script>
  10. </head>
  11. <body  onLoad="LoadPage('houses.php', 'hlist');">
What I am trying to allow the new page being loaded by javascript to use the javascript contained in 'lightbox.js' and 'prototype.js'

I hope this better explains my issue, and thank you for your help so far
Aug 6 '09 #6
gits
5,390 Recognized Expert Moderator Expert
so you load a page into an existing one and want to call existing and already evaled javascript methods on the newly loaded content? ... that is quite easy done from the success-callback of the ajax-request. basically that is your loadpage-function ... or do i miss soemthing? in that function, after setting the innerHTML you may call all existing functions on that content.

are you getting any errors?

kind regards
Aug 7 '09 #7
FreshRob
12 New Member
Hello,

So far none of my code is evaled.
I have tried dynamically adding the javascript files, prototype and lightbox but with no luck.

Hopefully this will help:

index page loads java.js, prototype.js and lightbox.js

java.js puts houses.php into the div hlist on the index page

One other piece of information is that the javascript for lightbox is loaded using a class, as lightbox.js creates a new class on the index page.

Hope this clears things up
Aug 7 '09 #8
gits
5,390 Recognized Expert Moderator Expert
so in your index.php the scripts are present and therefor evaled already on pageload. that was what i meant. the problem seems to be that lightbox.js initializes on pageload so that nodes that are appended after pageload are not observed? it seems that calling the constructor again could fix the problem ... so try to call:

Expand|Select|Wrap|Line Numbers
  1. new Lightbox;
  2.  
after appending the content. in case that works we could try to improve that a bit :)

kind regards
Aug 8 '09 #9
FreshRob
12 New Member
Still No luck, I think I may have to try a different method for getting the results that I want. Thank you for all your help
Aug 9 '09 #10

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

Similar topics

54
8286
by: VK | last post by:
Mission statement: A mechanics to get text stream into browser from any Web location without reloading the current page. 1) This mechanics has to support *at the very least* IE 5.5 and higher and Firefox 1.5 and higher: but it may be completely different from one browser to another. It is important only to be able to build an uniformed interface atop of it.
4
7469
by: evgenyg | last post by:
Hello ! We have the following situation - when Ajax request is sent what's being returned by the server is usually an XML (which is used for DOM updates) but sometimes it's HTML which is a whole new page that should replace an existing one. I.e when we issue an Ajax request we don't know what will be returned and analyze the response to act accordingly. Now, the way to replace the current document with a new one used to be easy and...
1
16506
by: www.web20developers.com | last post by:
http://www.web20developers.com http://www.web20developers.com/index.php?option=com_content&task=view... Ajallerix : AJAX, simple, fast Web image gallery demo ; at Novell AJAX - microlink pattern tutorial : A microlink is a link that opens up
10
2129
by: J | last post by:
Hi, Ajax question: Can I retrieve an HTML page and use the DOM to grab stuff from the requested page in a similar fashion to an XML page requested in the same manner? Details: I'm requesting a web page by: myRequest.open("GET", "http://www.asite.com/page.html", true);
1
4031
by: geevaa | last post by:
http://www.phpbuilder.com/columns/kassemi20050606.php3 XMLHttpRequest and AJAX for PHP programmers James Kassemi Introduction: Although the concept isn't entirely new, XMLHttpRequest technology is implemented on more sites now than ever. Compatibility is no longer an issue (IE, Mozilla and Opera all support it), and the benefits to using it are amazing. There are too many PHP programmers avoiding any
13
3999
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, asynchronously. These tasks might take long time so I want to keep the user informed of the progress. The problem is that only the PHP script knows the progress, how can the web page gets these information from PHP script?
0
7190
by: Tarik Monem | last post by:
I have been working on an all AJAX/DOM web site which is set to go live today and I thought I'd share my discoveries with all of you whom have helped me when I have encountered different issues along the way. First, deep linking is not something that a completely AJAX web site should be able to do by it's very nature of everything being on one page basically. So how can a person deep link to something that is on one page? This question...
4
2140
daJunkCollector
by: daJunkCollector | last post by:
I am using AJAX to dynamically load content into a <div> layer. As it stands, I am loading .html's into the <div> layer and it works awesome. The problem is that when I try to replace the .html with .aspx the content fails to load and I receive an error. It is very possible that the method I am currently using will not work as I desire. Perhaps someone can point me in the right direction please. SO...the following code is stored in an...
11
3035
by: =?Utf-8?B?R2VyaGFyZA==?= | last post by:
I have run into a situation that if a page/tab that uses the Ajax toolkit (using .net version 3.5) is closed before the Ajax enable controls complete loading, then IE locks up. Does it in both IE7 and IE8. There is no issue when the controls are allowed to complete loading. Can you please tell me the best practice that handles this? Thanks.
0
8787
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8697
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9289
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9060
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6615
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5939
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4454
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3151
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2508
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.