|
Lumpy posted:
All the examples I looked at for using XMLhttpRequest used a variation of this, my original code actually split the original string into an array and read every single element into the innerHTML one at a time after some parsing. I mean, they used different .split() parameters. I guess I forgot to mention that this code never executed anyways. ajax.status was always 0, never 200, so it never reached that inner branch of code. If I'm understanding the w3.org reference for XMLhttpRequest, status 0 means file not found. Because of this, I thought, "oh maybe the url needs a more explicit address to find the file I'm looking for instead of a relative address like 'events.txt'." So, I also tried variations such as: "file://C:/blah/events.txt" and "C:/blah/events.txt" or, if the javascript strings were having an issue trying to figure which characters are escape characters, I also tried: "file:\/\/C:\/blah\/events.txt" and other variations, but I never got ajax.status to leave the 0 status. I'm still not entirely sure what I'm doing wrong, and the responses I found via google kind of had me wondering if this was even possible.
|
# ? Aug 10, 2010 17:00 |
|
|
# ? May 21, 2024 07:36 |
|
.status won't work outside http/https, being the http status code. And, really, XHR over file:/// isn't guaranteed to work, either.
|
# ? Aug 10, 2010 17:12 |
|
OddObserver posted:That actually works in general, due to Array.prototype.toString So we should always assume we can use an array like a string?
|
# ? Aug 10, 2010 17:36 |
|
Lumpy posted:So we should always assume we can use an array like a string? I can't be anywhere that definitive; never thought it out. Except, well, in most contexts where it matters it will indeed auto-coerce into a string value (not to be confused with a string object, of course), e.g.: A = ["A", "B"]; A + "C"; produces "A,BC". And, well, most DOM methods will likely use the ToString operator as well, but those things always have wacko special cases. JS might not be quite as sane as you might think. (See also valueOf). And, well, obviously, stuff like index properties --- which aren't standard in 3rd edition anyway, dunno about 5th --- wouldn't use the string coercion, and neither would for .. in and the like. See also auto-stringifying Selection object or whatever that was.
|
# ? Aug 10, 2010 18:26 |
|
OddObserver posted:I can't be anywhere that definitive; never thought it out. Except, well, in most contexts where it matters it will indeed auto-coerce into a string value (not to be confused with a string object, of course), e.g.: A = ["A", "B"]; A + "C"; produces "A,BC". And, well, most DOM methods will likely use the ToString operator as well, but those things always have wacko special cases. That was kind of my point. Telling beginners / people who are new to the language that assigning an Array literal where you want a string version of it as "generally OK thing" to do may not be in their best interests.
|
# ? Aug 10, 2010 18:45 |
|
OddObserver posted:.status won't work outside http/https, being the http status code. And, really, XHR over file:/// isn't guaranteed to work, either. Now I'm really lost, if neither of those work all the time, was it just impossible for me to do it this way? Lumpy posted:That was kind of my point. Telling beginners / people who are new to the language that assigning an Array literal where you want a string version of it as "generally OK thing" to do may not be in their best interests. I thought the same thing at first, until I couldn't get it to work. I have a C/C++ background, so I really didn't believe that assigning a string array to a location where I want a string to be read would work, either. Eventually, after not getting anywhere for a while, I decided that maybe I should just straight-up copy and paste what other people were saying worked. Anyways, thanks for the tips guys, some of this stuff went over my head when I was writing originally, but now I understand what the code was supposed to do. I'm still not entirely understanding what I should change if I wanted to it work in this case, though.
|
# ? Aug 10, 2010 19:57 |
|
Rainbow Pony Deluxe posted:Now I'm really lost, if neither of those work all the time, was it just impossible for me to do it this way? 1) XMLHttpRequest is meant for, well, http, so it does a lot of things that don't really make sense for local files (status could be faked as 200/403/404, but what about stuff that has to do with http headers?). I think you can probably get away with just checking readyState, though. 2) There are various security considerations involving file:/// that if I am not mistaken (I might be on this) tend to be handled differently between browsers. Probably not such a big deal when just prototyping, though, and of course production stuff will likely just use http anyway, won't it? Rainbow Pony Deluxe posted:I thought the same thing at first, until I couldn't get it to work. I have a C/C++ background, so I really didn't believe that assigning a string array to a location where I want a string to be read would work, either. Eventually, after not getting anywhere for a while, I decided that maybe I should just straight-up copy and paste what other people were saying worked. Edit: might be worth picking at the JS error console or such to make sure there are no security warnings or the like. OddObserver fucked around with this message at 22:04 on Aug 10, 2010 |
# ? Aug 10, 2010 21:56 |
|
AJAX question! I am running into race conditions due to everything being asynchronous. How can I ensure I have my data before proceeding? The following is my scenario! code:
This is turning into a gigantic mess very quickly just to ensure I have an object. Am I just approaching this from the wrong way? Is the callback-observer that I described the proper way to do things in javascript?
|
# ? Aug 11, 2010 16:45 |
|
NotHet posted:Is the callback-observer that I described the proper way to do things in javascript? I think so, yeah. You have to wait until you receive the contents of the file before proceeding anyways, right? So you can't do anything until onSuccess is called. So give onSuccess something to do after file.setData (execute the callback you describe). If there's another way to accomplish this, I'm all ears.
|
# ? Aug 11, 2010 18:00 |
|
NotHet posted:AJAX question! If you are just going to be spinning your wheels until you get your data, you might as well use a synchronous query (I'm using jQuery here because it's easy): code:
|
# ? Aug 11, 2010 18:20 |
|
But that will lock up the UI for as long as it takes to fetch the file, which could be half a second, but could also be two or three.
|
# ? Aug 11, 2010 18:39 |
|
epswing posted:But that will lock up the UI for as long as it takes to fetch the file, which could be half a second, but could also be two or three. Yeah, so you show a "Loading data!" thing... I guess was assuming that locking the UI wasn't an issue because nothing could / should happen until data was loaded. Apparently, I assumed wrong!
|
# ? Aug 11, 2010 18:51 |
|
I'm writing for a WebOS. Palm doesn't want you using synced queries in the first place otherwise I'd have done that right away. The problem with synced queries and the spinning wheel method is the entire device will lock up as it all runs in webkit. I'm just going to keep track of what callbacks have been called and once I hit the magic number fire off my final callback. Thanks for the advice
|
# ? Aug 11, 2010 19:08 |
|
Im trying to write a simple HTML page with javascript that can parse through a local XML file using XMLHttpRequest and populate some fields in my page with data from the XML file. Google Chrome throws "Uncaught Error: NETWORK_ERR: XMLHttpRequest Exception 101", IE tells me access denied at my open function call, and firefox tells me nothing is wrong but doesnt do anything. Here is my page code:
Any ideas what the problem might be? Gentle Marmot fucked around with this message at 23:52 on Aug 11, 2010 |
# ? Aug 11, 2010 23:50 |
|
Gentle Marmot posted:
1. Are you serving up the page via a web server, or file:/// url? 2. Why aren't you using jQuery? It makes life so much easier.
|
# ? Aug 12, 2010 01:23 |
|
Lumpy posted:1. Are you serving up the page via a web server, or file:/// url? Im using file:// I dont have a webserver to try this on right now. I have a linux box to gently caress around with this stuff on but im elsewhere on windows and I dont want to bother getting ruby and webrick going on here right now. Basically all I care about is getting information into a JavaScript file out of a locally stored XML file. quote:2. Why aren't you using jQuery? It makes life so much easier. This doesnt seem like it would particularly be a hard problem and I want to learn how XHR works before using a library. Also how much code could I really save doing this same problem with jquery, ive barely written any as it is. Edit: Jquery does look pretty sweet actually and im gonna mess around with that but I still want to know why this isnt working. Gentle Marmot fucked around with this message at 02:13 on Aug 12, 2010 |
# ? Aug 12, 2010 01:33 |
|
file:/// requests have status 0, not 200. HTTP status codes are written by the HTTP server, so if there is no server, there's no code. If you decide to go the jQuery route, cool, otherwise modify your status check: code:
|
# ? Aug 12, 2010 02:31 |
|
Sweet it works... in firefox. IE and google chrome still send the same errors but some searching around seems like chrome broke being able to look at local XMLs like this and I dont care about IE. Oh well, when I get back to my linux box ill host something and mess with it there and Im gonna take a look into jQuery.
|
# ? Aug 12, 2010 02:43 |
|
Gentle Marmot posted:Sweet it works... in firefox. IE and google chrome still send the same errors but some searching around seems like chrome broke being able to look at local XMLs like this and I dont care about IE. As Supervillin said, "stuff" is different when not served via http. Chrome actually decided to follow the correct way of doing things with file:/// URLs ( no cookies, etc. ) that "broke" many a thing that had been done using the up until that point "incorrect but everyone did it" way.
|
# ? Aug 12, 2010 05:04 |
|
Testing ajax over file:/// is a bitch. I just set up lightttpd and point my browser to localhost when I want to do that stuff. It's ridiculously easy to setup on linux: 1 apt-get install it 2 set permissions on /var/www so that you can edit it 3 put your files in there 4 point your browser to http://localhost/blah
|
# ? Aug 12, 2010 05:14 |
|
Lumpy posted:As Supervillin said, "stuff" is different when not served via http. Chrome actually decided to follow the correct way of doing things with file:/// URLs ( no cookies, etc. ) that "broke" many a thing that had been done using the up until that point "incorrect but everyone did it" way. There are also security considerations involved. For example if a browser permits reading of absolute file:/// URLs, and not just things in the same directory, if a user is tricked to open a local/untrusted html file in that browser, it appears quite possible to do things like steal their cookies and ship them over the network to some outside host.
|
# ? Aug 12, 2010 05:35 |
|
Gentle Marmot posted:Sweet it works... in firefox. IE and google chrome still send the same errors but some searching around seems like chrome broke being able to look at local XMLs like this and I dont care about IE. I'm not sure what the issue is in IE, but as far as I know, Chrome won't let you load local files with ajax (using jQuery or not) unless you open it with either "--allow-file-access-from-files" or "--disable-web-security". At least that's how I got it to work without having a web-server up. Also, for IE, depending on which version it is, don't you want to make a "new ActiveXObject("Microsoft.XMLHTTP");" instead of an XMLhttpRequest? Although, I think IE7 supports this, so I don't know what the issue is.
|
# ? Aug 12, 2010 09:30 |
|
I'm creating a .pac file for our computers here at work, and we're rolling out a new proxy appliance that has an issue with a certain tool our agents use and I'm getting stuck trying to work around this. I'm pretty sure whats happening is the site I'm trying to work around meets several of my if statements. How does one go about telling it to stop processing after an if condition is true. I know this is basic, but I have no idea about javascript or coding in general, and have only got this far learning as I go from sparse info about .pac files on google So basically the if statements in the .pac are laid out like so (this is a very truncated version) code:
I'm guessing I might have to put some if / else if / else in there, but I'm at a loss to be honest.
|
# ? Aug 12, 2010 23:30 |
|
skipdogg posted:I'm creating a .pac file for our computers here at work, and we're rolling out a new proxy appliance that has an issue with a certain tool our agents use and I'm getting stuck trying to work around this. Your code *should* work, since there is a return in every IF. At least I think there is, but your crazy formatting makes it hard to tell. The following behaves as expected: 'a' is matched, and the function returns, so the 'b' if statement doesn't run. code:
Lumpy fucked around with this message at 23:59 on Aug 12, 2010 |
# ? Aug 12, 2010 23:54 |
|
innerText in IE returns the text of an element without HTML tags or newlines. textContent in Firefox returns the text of an element without HTML tags, but maintaining newlines. I want textContent's style in an innerText browser. Is there any easy way of doing this? I'm basically using these to scrub input into a chat app to get rid of any HTML tags that have been entered, but I also want to keep whitespace, which means innerText is not going to cut it. I'm willing to abandon textContent if it means getting this all working in IE as well. Any ideas?
|
# ? Aug 16, 2010 22:08 |
|
Golbez posted:Any ideas? My knee-jerk reaction was "use jQuery: $('#id).text()" But I would have looked oh so very dumb: quote:(Due to variations in the HTML parsers in different browsers, the text returned may vary in newlines and other white space.) So, my second knee-jerk reaction is that if it were doable, jQuery would probably have done it. So... maybe "use jQuery: $('#id').html()" and then scrub the html out yourself? But: quote:Some browsers may not return HTML that exactly replicates the HTML source in an original document. For example, Internet Explorer sometimes leaves off the quotes around attribute values if they contain only alphanumeric characters. Might be less of a problem? Alternately this might be of use: http://eligrey.com/blog/post/textcontent-in-ie8 (i.e 8 only?)
|
# ? Aug 17, 2010 00:03 |
|
KuruMonkey posted:My knee-jerk reaction was "use jQuery: $('#id).text()" I did try .text(), and it does indeed produce different results in different browsers, exactly the same as if I had used textContent and innerHTML. I also tried a loop using node.data (seen here) but got the same results. You have a point about jQuery; for all they talk about pure browser compatibility, it does seem notable that they would be specific about that command not being universal. So this is harder than it seems. Good job, Microsoft. As for scrubbing the HTML myself, that sounds difficult, know any libraries/jQ plugins for it? I mean, I guess, worst-case, I could either live with the whitespace issue, or just make HTML safe (html entities) for IE browsers and clean it in FF. This would be simple if it were being passed to PHP, but this is a chat app so it needs to display what they just typed in, and I've noticed that means executing any HTML they put in as well. (Found that out while copying and pasting some random webpage and it tried to download a new javascript file) As for the last link you posted, the link to his js file brings back a 404. And it's minified, so even if it was there it'd be difficult to see what makes it work.
|
# ? Aug 17, 2010 14:32 |
|
TBH at this point all I can do is google "jquery strip html" - which I shall leave as an exercise for the reader For the comedy option, of course... You could write a simple HTML stripping service in PHP and call it from JS
|
# ? Aug 17, 2010 14:42 |
|
KuruMonkey posted:TBH at this point all I can do is google "jquery strip html" - which I shall leave as an exercise for the reader But then there'd be a noticeable delay between them hitting enter and their own text appearing on the screen.
|
# ? Aug 17, 2010 14:45 |
|
I am putting together a website for a library, and they are going to be adding a pdf document to a page every so often. I want to have some javascript to find all the files in a subfolder and build links to them in a table whenever you go to the page, so that it automatically picks up the new documents without having to manually update the page every time you go to it. How would this be done?
|
# ? Aug 20, 2010 09:34 |
|
You'd need to do it back-end. Javascript can't read from the file system, for security reasons.
|
# ? Aug 20, 2010 09:51 |
|
Sergeant Rock posted:You'd need to do it back-end. Javascript can't read from the file system, for security reasons. You could do it in JS if you have directory indexes turned on (not a good idea), but it would be pretty bad indeed.
|
# ? Aug 20, 2010 17:15 |
|
Piell posted:I am putting together a website for a library, and they are going to be adding a pdf document to a page every so often. I want to have some javascript to find all the files in a subfolder and build links to them in a table whenever you go to the page, so that it automatically picks up the new documents without having to manually update the page every time you go to it. How would this be done? Define "every so often." If it's once every couple of days, is it really that big of a deal to do it by hand?
|
# ? Aug 23, 2010 23:16 |
|
Golbez posted:innerText in IE returns the text of an element without HTML tags or newlines. Magic: code:
|
# ? Aug 23, 2010 23:31 |
|
Is there a way that I can replace one element with another? I'm writing a greasemonkey script and am trying to replace td elements with divs. I also need to preserve the class / ID attributes.
|
# ? Aug 24, 2010 18:36 |
|
emoltra posted:Is there a way that I can replace one element with another? I'm writing a greasemonkey script and am trying to replace td elements with divs. I also need to preserve the class / ID attributes. code:
|
# ? Aug 24, 2010 18:56 |
|
Mackerel, the Thief posted:
Yeah, I just needed to ask about replacing the elements because it seems like all of the replacement tutorials completely replace the inner content. Thanks a bunch!
|
# ? Aug 24, 2010 19:03 |
|
emoltra posted:Is there a way that I can replace one element with another? I'm writing a greasemonkey script and am trying to replace td elements with divs. I also need to preserve the class / ID attributes. Uses jQuery, but does what you want, and gets all attributes: code:
|
# ? Aug 24, 2010 19:14 |
|
Lumpy posted:jQuery Brevity version: code:
|
# ? Aug 24, 2010 19:42 |
|
|
# ? May 21, 2024 07:36 |
|
Mackerel, the Thief posted:Brevity version: You have a couple variable names to cut down one letter mister. He might be able to understand those parts.
|
# ? Aug 24, 2010 19:53 |