JavaScript - Uploading Text File On Server
Dear friend ,
I am uploading text file on html page , that text file lies on desktop and getting updated at every hour . I will keep my html page on server so how will it upload that text file from my desktop ? it is being generated by one cloud sensor . Similar TutorialsI have the following JavaScript (see below). The script requests an XML file from the server and displays it on the page. The script works fine when the requested XML file is stored on the same server as the script. The problem is when I try requesting an XML file from an external server such as the National Weather Service. I get an error. If I take the XML file from the National Weather Service and save it to my server it works. Why can't I use my script to request XML files stored on external servers? Thanks in advance for any help. Javascript Code Code: window.onload = initAll; var xhr = false; function initAll() { document.getElementById("makeTextRequest").onclick = getNewFile; document.getElementById("makeXMLRequest").onclick = getNewFile; } function getNewFile() { makeRequest(this.href); return false; } function makeRequest(url) { if (window.XMLHttpRequest) { xhr = new XMLHttpRequest(); } else { if (window.ActiveXObject) { try { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { } } } if (xhr) { xhr.onreadystatechange = showContents; xhr.open("GET", url, true); xhr.send(null); } else { document.getElementById("updateArea").innerHTML = "Sorry, but I couldn't create an XMLHttpRequest"; } } function showContents() { if (xhr.readyState == 4) { if (xhr.status == 200) { if (xhr.responseXML && xhr.responseXML.contentType=="text/xml") { var outMsg = xhr.responseXML.getElementsByTagName("choices")[0].textContent; } else { var outMsg = xhr.responseText; } } else { var outMsg = "There was a problem with the request " + xhr.status; } document.getElementById("updateArea").innerHTML = outMsg; } } HTML Code Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>My First Ajax Script</title> <script type="text/javascript" src="script01.js"></script> </head> <body> <p><a id="makeXMLRequest" href="http://www.weather.gov/xml/current_obs/KOJC.xml">Request an XML file</a></p> <div id="updateArea"> </div> </body> </html> Hi, I have searched the web for many tools to upload a file and shows it progress, but they all seem to use, flash, codebehindfiles, php etc. I was looking for one that used pure Javascript was wondering if anyone could help? Thanks Marcel. Hi, I am trying to access an XML file from a server in my JavaScript code. I have an XML file like this: -<stream version="1.2"> -<room id="simulator" time="128168557915"> -<dimention id=0 x="1.25" y="2.00"> <m mcu="160" sid="75"> </dimention> </room> -<room id="simulator" time="128168557928"> -<dimention id=0 x="1.95" y="1.86"> <m mcu="160" sid="55"> </dimention> </room> </stream> this file is generated by an application and I can access it from a URL ( since I am using the simulator for this application the XML is accessible from http://localhost:8081/feed/demo) This xml file is updated every few seconds and constantly growing. I have a javascript code which I've added the following code to it in order to use the data from XML file: <script type="text/javascript"> if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET","http://localhost:8081/feed/demo",false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; document.write("<table border='1'>"); var x=xmlDoc.getElementsByTagName("room"); for (i=0;i<x.length;i++) { document.write("<tr><td>"); document.write(xmlDoc.getElementsByTagName("dimention")[i].getAttribute("x")); document.write("</td><td>"); } document.write("</table>"); </script> Now here comes my problem: if I have the XML file saved on same drive as html page and I address it like this: xmlhttp.open("GET","floor.xml",false); it works fine, but when I pass the URL it doesn't. is there anything else I should do in case of loading the xml from URL? my second question is that I want to use the text values returned by xmlDoc.getElementsByTagName("dimention")[i].getAttribute("x") in an if statement like this : if (valuereturned = 2.00) { do sth } what is the best way to do that, since the returned value is a text. I need the answer ASAP and I really appreciate your help, thanx :-) I am wanting to setup a dependant drop down where when a user clicks on the first drop down, it changes the contents of the second. The way I intend to do this is via a csv file. I have found several scripts but I have been unable to get them to work. Two of which a http://answers.yahoo.com/question/in...3114347AA7GYJ7 http://purbayubudi.wordpress.com/200...ng-javascript/ The first is the better option from what I can see. but the problem is readyState seems to be always 1. I am wondering if someone could perhaps give me a few moments to see if I can get this to work or suggest a better solution. I don't want to use a database approach, at least not yet. So, this is my last problem. If I can nail this, then the website will be completely AJAX driven, and will be spectacular. It took me a while to figure out just how to ask the question. lol Now it is really simple. 1) When I hit the button, in the simplified example below, the website sends a code to the server. 2) The server then re-writes the "xyz.js" JavaScript file with a new array of values. Is there any way to re-retrieve that JavaScript file, from the server to make it the current "xyz.js" rather than the old one that loaded on the client originally. I can get a new XML data file and re-submit that to the website, but how do I re-retrieve the new JavaScript code? Code: <html> <head> <script src="xyz.js" type="text/javascript"></script> </head> <body> <button onclick="onload();">Change</button> </body> </html> well i'm kind of new to this website and scripting with javascript but i am wondering: in a client side .js file i have some coding which results in a string which is stored in a variable called exportData now i want that string to be written into a text file on a server but how do i do that? it is not local on the client's pc and i can't find how to do it anywhere... can you guys help me? greetings, Fady Hello, Is there a way using javascript to have it check if a file exists on the server? I'm trying to check for a file on my server without having to refresh the open webpage. If this can't be done with javascript, do you know which webpage languange can execute this? Thanks I'm attempting to pull the hidden iframe file upload trick using javascript. I've go my form file upload and iframe fine, but I can't figure out what to do when it gets server side. There seems to be relatively no documentation on how to handle uploaded files in server-side javascript. Ideas? I'm at a loss.
Hi there, I have a photo editing business with many people working in Photoshop. I am currently developing a web based application (joblist) using Javascript and PHP which should allow the photoshop designers to browse and open files/images directly from joblist/web browser into photoshop. The reason I want this instead of browsing folder is that I have a database where I store who worked on which file, when and how long it took. The concept is that, designers will select a file and click on start, as soon as they click on start the original file will open in Photoshop and there will be an entry into database (using PHP). Once they finish the task they will close the file and click on Finish button. My joblist application will be published in a local server and the file will be open on a local network, so when they save the file it will be saved where the source file is located in (local server). The application should work in both PC and Mac. Anybody can help me to write the code (PHP or Javascript) which can open the file from browser (local server) directly into desktop application e.g. PHotoshop or Illustrator? Thank you very much I look forward to someone's real help! Best regards Mr. Sumon www.clippingpathindia.com Hi there, Can anybody help me to write php/javascript code which will allow users to open files directly from web browser into desktop application? Here is the specification: I have a photo editing business with many people working in Photoshop. I am currently developing a web based application (joblist) using Javascript and PHP which should allow the photoshop designers to browse and open files/images directly from joblist/web browser into photoshop. The reason I want this instead of browsing folder is that I have a database where I store who worked on which file, when and how long it took. The concept is that, designers will select a file and click on start, as soon as they click on start the original file will open in Photoshop and there will be an entry into database (using PHP). Once they finish the task they will close the file and click on Finish button. My joblist application will be published in a local server and the file will be open on a local network, so when they save the file it will be saved where the source file is located in (local server). The application should work in both PC and Mac. I have already done all other part of the application except file opening directly from browser to desktop application functionality. Anybody can help me to write the code (PHP or Javascript) which can open the file from browser (local server) directly into desktop application e.g. PHotoshop or Illustrator? Thank you very much I look forward to someone's real help! Best regards Mr. Sumon I would like to ask is it posible to add text from a text file to a text area on a page.. Philp if you read this i am not asking for a javascript code i am asking wether or not it can be done. P.s if your a nice person like philp is not and you want to private message me if you have one I'm having major pains trying to figure this out. I'm kind of new to Javascript, I need to open a text file from an external server, store each line in an array, then search that array for a certain word (HIGH), and if it exists then write something to the webpage, and if not, write something else. Here is what I have so far: Code: <html> <head> <title>Test</title> <script> <!-- function test(x) { if (wxd1txt.readyState === 4 && wxd1txt.status === 200) { // Makes sure the document is ready to parse and Makes sure it's found the file. var wxd1text = wxd1txt.responseText; var wxd1array = wxd1txt.responseText.split("\n"); // Will separate each line into an array var wxd1high = wxd1array.toString(); //Converting the String content to String //var highsearchreg = new RegExp("HIGH"); //var wxd1high = wxd1array[x].search(highsearchreg); document.write(wxd1high); if (wxd1high.search("HIGH") >= 0){ document.write("HIGH RISK");} else { document.write("NO RISK");} } } //--> </script> </head> <body> Hi! <script> <!-- var Today = new Date(); var ThisDay = Today.getDate(); var ThisMonth = Today.getMonth()+1; var ThisYear = Today.getYear(); var Hour = Today.getHours(); var Day2 = Today.getDate()+1; var Day3 = Today.getDate()+2; if (navigator.appName != "Microsoft Internet Explorer") { ThisYear = ThisYear + 1900;} if (ThisMonth < 10) { ThisMonth = "0" + ThisMonth;} if (ThisDay < 10) { ThisDay = "0" + ThisDay;} if (Hour == 2 || Hour == 22 || Hour == 23 || Hour == 0 || Hour == 1) { var wxHourd1 = 0600} else if (Hour >= 3 && Hour <= 10) { var wxHourd1 = 1300;} else if (Hour >= 11 && Hour <= 13) { var wxHourd1 = 1630;} else if (Hour >= 14 && Hour <= 16) { var wxHourd1 = 2000;} else if (Hour >= 17 && Hour <= 21) { var wxHourd1 = 0100;} //var wxurld1 = "http://www.spc.noaa.gov/products/outlook/archive/"+ThisYear+"/KWNSPTSDY1_"+ThisYear+""+ThisMonth+""+ThisDay+""+wxHourd1+".txt"; var wxurld1 = "http://www.spc.noaa.gov/products/outlook/archive/2010/KWNSPTSDY1_201005101300.txt" //(High risk day for testing) //document.write(wxurld1); //Use this to verify this section is working if (window.XMLHttpRequest) { wxd1txt=new XMLHttpRequest(); } else // IE 5/6 { wxd1txt=new ActiveXObject("Microsoft.XMLHTTP"); } wxd1txt.open("GET", wxurld1, true); wxd1txt.onreadystatechange = test(); // --> </script> </body> </html> When added to a webpage, nothing shows up except the "Hi!" and there are no errors in the Javascript Console in Google Chrome. Is this possible with Javascript, and if so, what am I doing wrong or not doing? Also, I have 2 URLs, one is a text file that has the HIGH text I want for an example, the other is the current file, which shouldn't have HIGH in it (unless the weather in the US turns really bad) Is allowing a button a create a text file a security issue? If so, how do I collect the names of users who have clicked a certain button?
Hello, I am building a web application that has quotes on it. I am planning on having all the quotes stored in a .txt file. A line space would separate the quotes. Example: "Blah Blah" "Idk what blah" "sure you do" Would this be using Javascript to pull the quotes from the txt file for use in my page be best? I need it to pull all the quotes. Reason for having it like this, I am also planning on having a random quote page where it just pulls 1 quote instead of showing all of them. I'm also open to other ideas here! David Faircloth hi, i have looked all over the internet but i can't find anything that works. All i want to do is simply read from a text file. Thanks Is there any possibility to write a text file using Chrome/FF? On the other words, writing a text file w/o using ActiveX. Thank you.
I'm pretty much lost at javascript, and unfortunately can use php to accomplish this, so here goes........ I have existing html page that includes a Week #. ie, 1, 2, 3, 5.... and so on. I'd like to be able to have a text, csv, or similar file that I can update on frequent basis that will list a Week # and than custom field of some type. (likely a date or unix time stamp). Is there a way to open a text file (or csv, etc) in javascript. Than be able to compare and get the correct data? Off the top of my head, I think its possible, and would involve something like the following? 1. Create a csv file like below 1, this is custom, my other custom 2, some more, and this too 3, and somthing, see spot run 2. Next would be have a javascript open and read the file. You would assign a variable name to each 1st, 2nd and 3rd item of each line. Than the script would loop through each line until it found a a match of Variable 1 to the Week your looking for. You could then parse out and use the other variables from that line. Any of that make sense? I hope to try and experiment some later today or tonight if I can, but javascript is still pretty foreign to me. Dear frnd I wanna read on html page , and i have script : " [I]<html> <head> <script type="text/javascript" language="javascript"> function Read() { var Scr = new ActiveXObject("Scripting.FileSystemObject"); var CTF = Scr .OpenTextFile("C:\\123.txt", 1, true); data = CTF .ReadAll(); document.write("<pre>" + data + "</pre>"); CTF .Close(); } </script> </head> <body onLoad="Read()" > </body> </html> [I] " But as its using activex control not allowing in all browser . Have you any other way with pure js to read the file contains ? or allowing activex in all browser ? Im trying to use javascript to search a text file. text file is like this... 1111111[TAB]Project Name[TAB]Application1 2222222[TAB]Project Name[TAB]Application2 Im trying to get the javascript to let a user search for number or project name, if found it displays all the info if found. application1 or application2 (whatever is in the 3rd area) The text file can also be seperated by commas, either way is fine. can anyone help with this. ? Hi, i want to open a file in a text area, such that the user can either browse for a file and when selected it will open in a text box on the page, or the user can select a file from a list of active links on the page and this will open in the text area. I am new to java and dont know where to start on this, i have been browsing resources on the internet but have not found anything to get me started, would anybody be able to help? Thanks |