I have studiously avoided JavaScript for many years now, having had to
deal with it back in the Netscape 4 days and subsequently going insane.

I'm now trying to dip my toes back into the JS water, and am working
with Prototype to provide server-side validation using the Ajax
functionality of Prototype.  In general, this is working just fine, but
there's one part of the experience that's driving me nuts.

Assume this sample code (-[ ]- come from the fact this is in a Smarty
template):
function processRequest() {
   var url = '-[$serverpath]-';
   var parameters = Form.serialize($('dataform'));
   var myAjax = new Ajax.Request(
       url,
       {
           method: '-[$ajaxMethod]-',
           parameters: parameters,
           onSuccess: function(request, json) {
               // Clear all error spans
               clearFormErrors();
               // Clear the result span
               clearStatusNotification();
               // Set the result text.
               $('result').update(json.resultText);
               $('result').show();
               // Check the JSON data
               if (json.success == false) {
                   // Server said life is bad
                   if (json.errors) {
                       new Insertion.Top('errors', '<span><ul>');
                       json.errors.each(function(m) {
                           insertion = '<li
id="error_'+m+'">'+json.message[m]+'</li>';
                           new Insertion.Bottom('errors', insertion);
                           $('error_'+m).addClassName('error');
                       });
                       new Insertion.Bottom('errors', '</ul></span>');
                       $('errors').addClassName('errors');
                       $('errors').show();
                   }
                   $('result').addClassName('error');
                   new Effect.Highlight($('result'),
{startcolor:'#ff0000', endcolor:'#ff3333', restorecolor:'#ff3333',
duration: 3.0});
....

If there is a single mistake on any of the lines in the onSuccess
anonymous function, the JS appears to stop processing, and not a single
error gets logged in Firefox's console (nor in Firebug).  This has led
to several hours of me looking at the code and going 'But everything
looks right!', only to realise (after copious use of alert()) that I
called a custom function by the wrong name.

What methodology/function/voodoo can I use to get JS errors to occur
when the anonymous function goes belly up?  I'm using an RC of the 1.5
version of Prototype to get the automatic JSON header parsing
(controlled environment, not a public site).


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on 
Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to