Hi guys, I''m using an iframe to upload files to a server, and after that, I''d like to add a reference to those files in my MySQL database. (I''m using PHP.) I created a function on the main page that holds the iframe, that makes the request. fileToDatabase = function(file, user, client) { console.log(''Added file to database:''); new Ajax.Request(''yourfiles_process.php'', { parameters: ''uploadFile='' + file + ''&user='' + user + ''&client='' + client, onSuccess: function(transport) { console.info(transport.responseText); //call to firebug }, onException: function(error) { console.error(error); } }); } If I call this function from the main page, it works fine. But if I call it from the iframe like this: window.parent.fileToDatabase(''somefile.jpg'', ''21'', ''11''); my request throws an exception. (I should note that the call to "console.log" works perfectly well.) Firebug puts a big red X over my POST request, and the console shows this as an error: "Object transport=XMLHttpRequest options=Object". Under that header, I can see that nearly all my transport values are false. Does anyone have any idea why this might be happening, and if I can fix it? --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
I guess no one else has experience my problem.. :( --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
To be honest, I''ve never tried to use functions declared outside of an iframe within an iframe. I know iframes have their own document.domain property so I wonder if there isn''t a problem using the XHR to communicate from the iframe to your server. Why are you calling the javascript from the iframe? If I remember correctly, the last time I was playing with iframes, they would respond onLoad events so you can use Event.observe to see when the iframe changes (that is when the upload is complete) and then call the function from the main page. - Dash - brandy wrote:> I guess no one else has experience my problem.. :( > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
David, the problem with simply detecting a change in the iframe is that (a) I won''t have the name of the file that was uploaded, and (b) I won''t know if the upload was actually successful or not. Of course, I haven''t actually tried to use Event.observe on an iframe before so maybe I am wrong. One interesting thing to note: this works like a charm in Safari. I think I will continue testing in other browsers to see what happens. Thank you for your suggestions. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Ok, it appears that this fails in Firefox (Mac & PC) and Camino, and works fine in Safari, Opera, and IE7. So at least I know now to search for Mozilla-related issues! --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
It worked for me in FF, so it''ll happen with some work. What you can do is have your uploading process put very specific information into your iframe -- even number codes if you like that sort of thing -- and then get at the contents of the iframe to see what uploaded. If there''s a filename in the iframe, then you can use that to update your database or if there''s an error message, use an alter() box or put the information on the screen with an update() call or something like that. You''ll have to google around until you find out exactly how to get at the document text of an iframe (it''s not iframe.innerHTML unfortuately) unless someone else here chimes in on how it works; I''ve forgotten. - Dash - brandy wrote:> Ok, it appears that this fails in Firefox (Mac & PC) and Camino, and > works fine in Safari, Opera, and IE7. So at least I know now to search > for Mozilla-related issues! > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
David, I fixed my problem by writing my Ajax.Request into the parent document, rather than calling it directly. Prototype then processes this code, and no more exception! Seems to be working in browsers other than Firefox, too. I am sure your method would work well, too, so I appreciate your input regardless. By the way, for anyone who happens across this thread later, the exception is not visible in the regular Firefox error console. I discovered it only because I use Firebug, which showed me that the request had failed. I used the onException handler (in the Ajax.Request) to try to see where the error originated, although it wasn''t particularly helpful. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---