View Full Version : Trying to understand what this does

01-18-2012, 03:09 AM

I am very new to JavaScript. I am trying to understand what this does and I am hoping someone here can help. A user fills in some data for a search and results are displayed on the page but there is no option to save the results. I would like to be able to just dump them into a text file, but I have no way of changing this code.. so I'm thinking if I could find out specifically what this is doing then maybe some other tool or command can be used to get the results and save them into a file (maybe wget?? or something). Here is the code:

<script type="text/javascript">//<![CDATA[
$(document).ready(function() {$.get('\x2fTraceMessage.mvc\x2fAsyncMessageList\x2f736251', { s:'google\x40google.com', r:'yahoo.com', d:'1\x2f10\x2f2012 2\x3a18\x3a37 AM', e:'1\x2f16\x2f2012 2\x3a18\x3a37 PM', i:'', a:'-5' }, function(data) { $('#message_trace_list').html(data); });

Thanks in advance for any help!

Philip M
01-18-2012, 08:36 AM
JavaScript is purely a client-side language, and unless used with an Ajax call has no capability to read from or write to a file (except a cookie), communicate with the server, access a database, the client's operating system or the Windows registry, or alter the default behaviour of the browser.

You must use server-side coding to save the information to a file.

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

01-18-2012, 09:13 AM
With modern browsers including IE8 you do have access to save data in localStorage instead of in a cookie (cookies get transferred to the server and back each time the page is processed while localStorage doesn't) - you don't have access to actually read what is stored in localStorage from anywhere other than JavaScript running on the same site though (the same as cookies). The biggest difference between cookies and localStorage (apart from whether they share the data with the server or not) is how much data you can store - plus that IE7 doesn't understand that localStorage exists.