Using XMLHTTP and DOM I'm able to load new HTML page content.
I'd now like to load small snippets of javascript with the HTML markup
and have that <script> incorporated into the page. If any of the loaded
script exists outside a function definition (eg: a call to a function),
I'd like that code to be executed as soon as its added to the DOM.
Can anyone suggest the best way to do this? I've Googled but not found
anything comprehensive. Do I need to use the eval() method or is there
a better way?
i want to postload javscript from another javascript. This works fine in firefox and IE6 for macIE i can use an Iframe to load the code and inject it with insertAdjacentHTML The problems arise with safari and opera. Both load the new code with XMLHttpRequest, but the code is no 'executable'
To make this possible on IE i had to use the magic 'DEFER' attribute. (Sync or Async ist not the issue)
I wrote an "ajax" script that pulls dynamic content into a div container via xmlhttp. There is a variety of lists on this page that are all ajax. Basically the up/down arrows in the Music, Photos, Users, Community etc boxes have this javascript funtion that replaces the innerHtml properties of a div to some response data from an asp.net object.
In IE these up/down arrows works fine and pull in data, but in FireFox the divs come up with "Undefined" in the div instead of the data.. Code:
I don't know enough about the technology yet to know whether this is a ridiculous question-- but is there no cross-browser javascript implementation of XMLHTTP and SOAP for use in calling web services?
It looks as though MSFT expects the client to be running Windows and ActiveX and have certain DLLs installed; and Mozilla seems to have its own implementation of SOAP. Is it possible to implement these protocols in pure client-side javascript?
Ive been banging my head on the wall for hours with this one, hopefully someone will know what Im doing wrong here :
The Goal:
I have an xml file that is generated on the fly via JSP which I want to load into a Microsoft.XMLHTTP ActiveX object and manipulate via javascript on the client side. Data is retreived from the server at the request of the javascript without having to reload the page.
The Problem:
For the JSP to dynamically output xml, the file must have the extension JSP, which is set to the mime type of dynamo-internal/html on the server side (as we are using ATG Dynamo). But the javascript on the client side will not retrieve anything unless the file extension is ..xml (or the mime type is recognized as text/xml). So the only way I can get it to work is to change the extension to .xml, which then of course amkes it so that the server will not process any of the JSP code.
Ive tried to override the mime type within the javascript, using the setRequestHeader method after opening the file, but no luck. A call to alert the value of req.responseXML.xml after the send() turns up empty. Ive only gotten it to work if I use a static xml file in palce of the jsp. Sample of the javascript code is below:
if (window.XMLHttpRequest) { // branch for native XMLHttpRequest object - THIS WORKS req = new XMLHttpRequest(); req.overrideMimeType("text/xml"); req.onreadystatechange = processReqChange; req.open("GET", "models.jsp?cId=300006&mId=TAC24", true); req.send(null); alert(req.responseXML.xml); //this gives me the resulting xml file } else if (window.ActiveXObject) { // branch for IE/Windows ActiveX version - NOT WORKING req = new ActiveXObject("Microsoft.XMLHTTP"); if (req) { req.onreadystatechange = processReqChange; req.open("GET", "models.jsp?cId=300006&mId=TAC24", true); req.setRequestHeader("Content-Type","text/xml"); req.send(); alert(req.responseXML.xml); //this gives me nothing } }
In looking at the following example the Microsoft gives (bottom of page):
I should note that I successfully got the script to work using the XMLHttpRequest object and the overrideMimeType() method. This works with FireFox and I think some Mozilla clients, but not with the all important IE5, which instead uses the XMLHTTP ActiveX control.=
I have created a Javascript menu for my site which uses frames. The first stage loads fine but I want two drill down menus ("About Me Menu" and "Projects Menu"). The pages load fine, but the images aren't displayed, instead the alt text is shown. The images come up after you "Mouse Over" them but not before......can anybody spot any errors in my code which could be doing this please. For info, I have 4 images for each button, to take into acount whether the button had been used and to give a mouse-over image for each state. I have also deleted the code for items 3-5 as they are commercially sensitive. Code:
As we all know, JavaScript is client side and php is server side, (the php code is 'allowed' to do stuff on the server that JavaScript cannot). The problem with php is that it timeout after a while, (and the user also has no clue as to what is going on for a long time).
I need to run a script on the server that could take a very long time.
So what I was thinking is mixing both JavaScript and PHP Something like,
<script> var endvalue = 1000; /* some number that the server can calculate quickly */ var i = 0 while (i<=endvalue) { /** call a php file that will do some work somefunction.php?someNumber=i */ } </script>
That way the server does the work, while the client keeps it going. Ideally I would also get a return value/string from the php script.
I am using this to load the client JavaScript for a web application when it is selected by the user) via an Ajax connection to the server.
I have found only two ways of loading new JavaScript after the web page is loaded.
1. Create a new script element (where head is the id of the head tag): var s = document.createElement('script'); s.setAttribute('type','text/javascript'); s.setAttribute('src', 'scripts/myscript.js'); s.setAttribute('defer', false); document.getElementById('head').appendChild(s);
2. eval() of a string sent from the server via XmlHttpRequest.
The first method does not work with Apple Macintosh Safari. There is an article on the apple support website http://lists.apple.com/archives/Web...r/msg00024.html
Does anyone know of any other methods that are cross-browser?
I already know about the IFrame workaround, but I have not been able to determine if that is really portable and practical. Does anybody have experience with this?
im trying to get values from a database and assign them to icons which display on my page. The icons that are generated on the page are generated in javascript- and they do work. Howver i want icons to hold the names that are in the database/table.
how would i do this? would this be using a query result in asp to get the values from the database?? how would i do this? please provide code or guide.
then, how would i assign the database value with the icons???? ive heard javascript arrays??? how would i assign the values??
I am working on a client's site and he has some external javascript code that his affiliates can put on their websites to fetch some data. However, when my client's site goes down, the affiliates' sites cease to load thus taking their sites down with it.
Is there any way I can have the javascript check to see if the website is up before loading, and if it is, run this: Code:
Here 'some_function' is opening the 'pagename' in a new customised window.
This page also contains a few images weighing 50kb. Now if I click the <a> links before the images are loaded fully, following happens (on my pc it works well but it happens when i test it online):-
1. The new page opens in a window as required 2. But the page loading is ABORTED and the images are not loaded.
I have been struggling with a cross browser solution to loading external javascript files on the fly.
I have been successful using the following code in IE6:
var newScr = document.createElement("SCRIPT"); newScr.src = "newScr.js"; newScr.type="text/javascript"; document.getElementsByTagName("head")[0].appendChild(newScr);
I believe the reason is that IE is loading the external file syncronously while Firefox is not. Is there an onload event for creating an element (if so I do not see it in Venkman). I have seen the solution of using XMLHTTP to load the script but I am trying to get around any dependency (atleast at this stage of the library) on activex.
I have an XML page I'm trying to load with javascript to display on Mozilla Firefox. I can get this to work on Internet Explorer but it would not work on Firefox. I can't figure out what I'm doing wrong. Can someone glance at my short piece of code below and tell me why this wouldn't work on firefox? Code:
I'm trying to do use XMLHTTP to do a POST in the following JavaScript snippet.
var xml = new ActiveXObject('Microsoft.XMLHTTP'); xml.open("POST", "http://some/url/", false); xml.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xml.send("username=myusername&password=mypassword"); document.write(xml.responseText);
This works fine in Internet Explorer 6 SP2. However, I would like to use https, rather than http. When I change the URL to https and reload the page, I get an error: "The download of the specified resource has failed". As a test, I tried running the same code in Firefox (changing the first line to "var xml = new XMLHttpRequest()"), and this worked for both http and https perfectly, although using https causes a dialog box to pop up asking the user to accept the SSL certificate. Unfortunately, I really need this to work in IE.
I found a couple of discussions on Usenet about this, but none that seemed to give me a clear answer to this issue. Does anybody know what might be wrong or how I might fix it?
Just playing around with xmlhttp at the moment. I was just wondering if there is any reason (browser compatibility etc) the response data has to be formatted in xml, or can I send csv or whatever else if the handler is up for it?
I've been looking into the possibility of using XMLHTTP for my enterprise application but I still have a question.
When you send the request to the server, how does the server know how to handle the request? (i.e. how do I specify what method to call in my java servlet?)
I'd appreciate any help on this.....I've only got a vaey basic knowledge of javascript and I am fluent in java.
There is a problem with XMLHttpRequest and Firefox when the function that makes the asynchrounous request is called from another window. The URL of the window does not change to the next page in which i am displaying the response.
I'm writing a script to send posts to a web forum. I find that MSXML2.XMLHTTP object could communicate with web server but I can't make it send cookie which is needed for post authentication. I have searched google and read some articles including: Code:
I've picked up a copy of "Foundations of Ajax" and was working through one of the initial examples and ran into a problem. xmlhttp.status always returns 0. I can run the following code and get the expected text returned from the server but only if I comment out the conditional that checks xmlhttp.status
<script type="text/javascript"> var xmlHttp; function createXMLHttpRequest() { if (window.ActiveXObject) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); alert('ActiveX xmlhttp object instantiated'); }
else if (window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); alert('Non-IE xmlhttp object instantiated'); } }
I don't understand how xmlhttp.responsetext can return the text in the file if xmlhttp.status returns 0. I'm running apache 2.055 on my local xp box. apache is a stock cfg except for vanilla changes I made to add php5.
I'm trying to translate an asp application, i have some difficulties with a particular line : --- Set myxml = Server.CreateObject("Msxml2.ServerXMLHTTP.4.0") ---
Classical ajax exemples rather use : [...] req = new ActiveXObject("Microsoft.XMLHTTP");
.... But i'm not sure the ActiveXObject is identical to the original : Set myxml = Server.CreateObject("Msxml2.ServerXMLHTTP.4.0")
I'm not an asp expert, can you give me some tips on that question ?