This was moved from Prototype: Core andymadonna -me
Hi, I'm new to using Prototype. I trying to use Ajax to make an interactive timeline of the 60s, but my Ajax request keeps failing. I have it on my live site for testing: http://the60s.andrewmadonna.com/timeline.html Here is a code snippet of the actual request: new Ajax.Request('timeline_backend.php', { method: 'get', parameters: {action: 'year', year: request_year}, onCreate: create_loader(), onFailure: alert("Oops!"), onSuccess: create_year(transport) }); -------------------------------- Tom Gregory You are not passing function references to the callbacks as you perhaps intend. You are instead passing the results of functions. Modify these lines: onCreate: create_loader, // No parenthesis onFailure: function () {alert("Oops!");}, // anonymous function onSuccess: create_year // Again, use a function reference, not a function result --------------------------------- andymadonna Thanks Tom, I modified it to what you said. But now it doesn't create the loader, and I know its executing the create_year function because I put in an alert to test it but it doesn't perform anything past that. Modified: new Ajax.Request('timeline_backend.php', { method: 'get', parameters: {action: 'year', year: request_year}, onCreate: create_loader, onFailure: function () {alert("Oops!");}, onSuccess: create_year }); --------------------------------------- Gareth Evans What is in your create_year function? ---------------------------------------- andymadonna Hi Gareth, The create_year function creates all the dates for that year on the timeline. I have it on my live site to test the code: http://the60s.andrewmadonna.com/timeline.html Here is the actual function: function create_year(transport) { alert("I am being executed!"); var timeline_content = document.createElement("div"); timeline_content.setAttribute("id","timeline_content"); var timeline = document.createElement("div"); timeline.setAttribute("id","timeline"); var line = document.createElement("div"); line.setAttribute("id","line"); var xmlDoc = transport.responseXML.documentElement; var loop_length = xmlDoc.getElementByTagName("date").length; var isBottom = false; for (var i=0;i<loop_length;i++) { var date_title = xmlDoc.getElementByTagName("date") [i].childNodes[0].childNodes[0].nodeValue; var date_text = document.createTextNode(xmlDoc.getElementByTagName("date") [i].childNodes[1].nodeValue); var date = document.createElement("div"); date.setAttribute("title",date_title); var date_line = document.createElement("div"); date_line.setAttribute("class","date_line"); if (!isBottom) { date.setAttribute("class","date"); date.appendChild(date_text); date.appendChild(date_line); isBottom = true; } else { date.setAttribute("class","date_bottom"); date.appendChild(date_line); var date_bottom_text = document.createElement("div"); date_bottom_text.setAttribute("class","date_element_text"); date_bottom_text.appendChild(date_text); date.appendChild(date_bottom_text); isBottom = false; } timeline.appendChild(date); } timeline.appendChild(line); timeline_content.appendChild(timeline); var next_arrow = document.createElement("div"); next_arrow.setAttribute("id","next"); next_arrow.setAttribute("class","arrows"); next_arrow.setAttribute("onclick","slide_timeline_next();"); var next_arrow_text = document.createTextNode("><br /><br / ><br />>"); next_arrow.appendChild(next_arrow_text); timeline_content.appendChild(next_arrow); var previous_arrow = document.createElement("div"); previous_arrow.setAttribute("id","previous"); previous_arrow.setAttribute("class","arrows"); previous_arrow.setAttribute("onclick","slide_timeline_previous();"); var previous_arrow_text = document.createTextNode("<<br / ><br /><br /><"); previous_arrow.appendChild(previous_arrow_text); timeline_content.appendChild(previous_arrow); document.body.appendChild(timeline_content); $('timeline').setStyle({ width: 8 * loop_length + 'em' }); } ---------------------------------- --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
