Topic: Asynchronous updates to a javascript file using AJAX

Hello,

I'm working on a rails application that utilizes the canvas element of HTML5. To save information, I write the steps done that a user takes to a javascript file. When the page loads, it loads this js file into a script tag, so the code executes. Right now, a user utilizes the canvas, and then clicks "Save" to commit the changes to the js file. What I want to achieve is changing from that, to saving it asynchronously while the user uses the canvas. So updates are done constantly, so people looking at the same canvas on different machines can see the updates constantly as well (which I will use a timer on reloading the script file or something). I realize this could potentially lead to a lot of server requests, and high load. I'm starting to get there on making this happen, but right now the changes arent saving at all, and some things are working a bit oddly. Here's the mousemove event code:

AGM.addEvent(canvas, 'mousedown', function(e) {
      WB.currentTool.setStarted(true);
      WB.currentTool.callStartAction(ctx, x, y, WB.currentTool);
      if(undoDisabled) {
        jQuery('#undo').attr('disabled', false);
      }
      // Experimental code for constant file writing
      
      jQuery('#five_whiteboard_drawing').attr('value', steps.join(''));
      
      jQuery.ajax({
        type: 'POST',
        url: path,
        data: hidden_fields.join('&'),
        success: function(data) {
          WB.tools.CLEAR.obj.callAction(WB.getCanvasContext('canvas'), 0, 0);
          var script = document.createElement('script');
          script.src = jQuery('#wbsource script').first().attr('src');
          jQuery('#wbsource').children().remove();
          jQuery('#wbsource').html(script);
        }
      });
    });

The first few lines are normal bits of code. They just call the current tool that the user has active. After the comment, I populate a hidden field in a small form (the save button), with a string of all the steps to re-run the canvas. This is what's used to write to the js file. I then write an ajax request that works similarly to the form. Hidden_fields array includes things like the authenticity token, the encoding, the five_whiteboard_drawing hidden field, etc. Upon success, I clear the canvas, and then replace the javascript file script tag with a new one.