I've been trying to create a 'loading page' for a from. When a user submitts a form, a loading animation is displayed on the page. Then I have javascript connecting to a url on my server that generates a dynamic file and returns it from memory. My problem is that I can display the text from this new file, but what I want to do is prompt the user to save the file locally. Is there a way to make this sort of conversion in javascript?
Say x in a XML Http Request Object ... meaning it's either XMLHttpRequest (firefox) or ActiveXObject (IE)
This line of code works in firefox... x.someProp = "someValue"; alert(x.someProp);
But in IE I get "Object doesn't support this property or method" I need to place a custom property on the object. Is there any way I can do that in IE?
I'm just starting to try out "Ajax" web programming and I've got a question.
AJAX is fairly straightforward. Javascript creates an XMLHttp object and then uses that to generate a hidden webpage with your results.
What I'd like to know is, how can I retrieve multiple values from an XMLHttp request?For example, if my request generated an SQL query that returned a Name, Address and PhoneNumber, could I get those values directly instead of parsing them out of the ResponseText?
This is my current handler:
function showResult(pge) { var url="getResult.asp?sid=" + Math.random() + "&q=" + pge xmlHttp=GetXmlHttpObject(stateChanged) xmlHttp.open("GET", url , true) xmlHttp.send(null) }
function stateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { //Complete, so show results. document.getElementById("myResult").innerHTML=xmlHttp.responseText; //How to get mulitple values here? } }
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.=
How do I explain this? I am grabbing several elements from my document and placing them in an array, using jQuery. When I test the Code: typeof this item, it returns as an Object, not an Array, which is problematic for IE. Firefox seems not to have an issue with Code: Object.length , but IE won't have any of that, so I need Code: Array.length or do I? In the end, I just want IE to know how many keys are in the Array/Object...
In addition to fetching JSON you might want to POST it back to the server, but there is no postJSON method. You cannot use the generic ajax method, either. What is missing is the complement of "eval" to turn a JavaScript object in to JSON. The JSON.stringify function from www.json.org (see json2.js in JavaScript section) does the trick, but it would be nice if jQuery incorporated that out of the box, to save some hunting time.
Using the jquery ajax method to set the "type" to "json" and the "content-type" to "application/json" send and recieve JSON, but you must use JSON.stringify to convert your outgoing object to JSON. P.S.. a lot of forgiving parsers have resulted in a lot of articles on JSON being wrong. would I like to mention that here. Property names are JSON strings. JSON strings have double quotes. Therefore, property names have to be surrounded with double quotes. Single quotes are not JSON strings and not legal (JSON is not JavaScript).
I think this is a problem converting (what is assumed to be) a string to numeric. or something like that.
rvs = s[i][j] * k; Firefox Error Console says: Uncaught exception: TypeError: Cannot convert 's[0]' to object rvs is just a (temporary, holding) variable. s is a [3][6] array on numeric values. i, j and k all happen to be zero. [Code]..
I'm trying to convert some Procedural code to be more Object Oriented and I'm stuck...
The page is really simple:
It's just a big picture w/ a caption under it, and a few thumbnail pics off to the side, that when clicked, replace the big picture as well as swap out the caption for a new one.
In the code (external JS file):
I've got 2 arrays:
One that holds the thumbnail image file URLs, and the other that holds the captions.
And a function:
I've created an object prototype that I can instantiate in order to:
1.) create the event: do the actual swapping of the thumbnail, and the changing of the caption.
2.) and attach that event to the thumbnail's link onclick event handler.
The code below is the closest I've come to making it work. The problem is that when I click any of the thumbnail links it only executes the last event instead of the one that corresponds to the link that was just clicked. Hopefully someone can take a look at my code and let me know what I'm doing wrong.
Simplified version of the code:
The x,y,z variable assignments are only in the window.onload function for the sake of clarity, but the event object instantiation block has to be in there for anything to work at all.
I know that the event0,event1,event2 objects work, and are attached to the onclick handler because they will swap the last thumbnail and caption when I click any of the thumbnail links. Of course that's the problem now... any click only activates the last event. It's like it attached the last event to all the onclick event handlers.
In fact, if I only create the event0 object, it works like it's supposed to... but when I create the event1 object, it does what it's supposed to and it takes over for event0. Creating event2 makes it take over for all of them. Each subsequent event# object seems to attach its own addy[ ] and caption[ ] to each previous x[ ] link.
I just got this script for a countdown on a website and I got it to work locally but when I upload it to the server i get the error "index.html:22 Uncaught TypeError: Object [object Object] has no method 'fancycountdown'".
I have checked to make sure all other javascript files are loading and they are and I can't figure out whats wrong. You can see it [URL]
I've been working on a function to convert nodeList and object properties to an array. The first question is with regards IE and checking whether the object provided is an HTML collection. The best I have come up with so far, is to test if it's an object, has an 'item' which is a function and has length. The second question is with regards slice.call and a while loop copy. I guess I need to do some profile/timing tests, but I'm wondering if the function merits a slice.call? or should I simplify?
Code JavaScript: // Some weirdness in IE regarding nodesList and typeof 'item' returning 'Object' // even though when alerted it returns 'function (){...}'. // Therefore having to use regExp.test() to check whether it's a function instead. // Note: _isNodeList isn't full proof. An object with the properties [Code]..
I have a jQuery object $('p').eq(1) and I would like to display its text equivalent '$('p').eq(1)' in an alert box ie I want the alert box to display $('p').eq(1).The alert box only displays [object Object] (as you might expect).I have used String() (and many others) but this does not work.If this cannot be done, is it possible to do the opposite ie to convert the string "$('p').eq(1)" to the jQuery object $('p').eq(1) ?
I have come across an issue that only happens with IE.I have a custom save function that is designed to handle different ajax submits but I will simplify it for debugging. The issue is that once I make a submit everthing is fine at first. Then once I try to submit a second time it craps out. I am checking to see if there is an onsubmit function and then executing it like so before continuing. After the inital submit it is no longer found. When I alert the typeof document on the form it returns object but when I add the onsubmit it says object expected or object is null or undefined.
Code:
function secureBarSubmit(formId) { alert(typeof document.getElementById(formId)); // object always alert(typeof document.getElementById(formId).onsubmit); // func first time then it is broken
Can assign a new function to a built-in object in Firefox:
But IE and Opera don't have a MouseEvent or HTMLElement that can be set up in the same way. Can you do this in IE or Opera, or just Firefox, and maybe Webkit?
Is there any way at all to create a new template object that inherits from the built in Date object so as to be able to add new methods to that child object without adding them to the built in Date object? I've tried everything I can think of and as far as I can tell it keeps referencing the Date function instead of the Date object and so doesn't work.
I have an object with a single Method to load content from a xml file. The problem is... how do I add a property to the object to store the data loaded?? I tryed adding a simple Array inside the object, but didn't work.
I am using a Photo Gallery script called Galleria which uses jQuery/JavaScript to display photos. On my index page load (only in Internet Explorer), a message box pops up saying "Message from Web Page [object Object]". After clicking OK the photo gallery loads and there is no problem.No idea how to fix this, or really what the error means. You can view the error from my site here