I have a website http://www.kanjimyblog.com which allows clients to include random Japanese characters on their blog or homepage. It is working fine with a PHP include which serves Javascript to the page, and is reasonably quick... Here lies the problem. Due to the nature of <script src=''...''></ script> includes, the page only renders once the external file has completed loading. So if the client puts the file on his left sidebar, the entire page hangs until my script has completed... Even if this is only a second, its a second too long... So I want to do this with AJAX or something similar, but cant get it working. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Please submit the code that isn''t working. On Aug 29, 9:22 am, junkmate <junkm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a websitehttp://www.kanjimyblog.comwhich allows clients to > include random Japanese characters on their blog or homepage. It is > working fine with a PHP include which serves Javascript to the page, > and is reasonably quick... > > Here lies the problem. Due to the nature of <script src=''...''></ > script> includes, the page only renders once the external file has > completed loading. So if the client puts the file on his left sidebar, > the entire page hangs until my script has completed... Even if this is > only a second, its a second too long... > > So I want to do this with AJAX or something similar, but cant get it > working.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Its not so much the code isnt working, its the idea. Internet browsers do not allow XMLHttp requests across different domains, due to security risks, so that rules that out. I also tried using an innerHTML update using the Javascript code setTimeout(script to run, 0) - which works great on all browsers apart from IE5, which crashes the browser when you revisit the page... Here is the code from the second example: CLIENT INCLUDES THIS ON THEIR EXTERNAL PAGE: <script type="text/javascript"> (function(){document.write(''<div id="unique_id"></div><p>''); s=document.createElement(''script''); s.type="text/javascript"; s.src="http://url_to_php_scrpt.php"; setTimeout("document.getElementById(''unique_id'').appendChild(s)",0);}) () </script> ABOVE SCRIPT CALLS THIS PHP SCRIPT: document.getElementById(''unique_id'').innerHTML +=''data_that_I_want_to_display''; This works great on all browsers, but it crashes IE if the same page is re-visited without a refresh... On Aug 29, 3:11 pm, Diodeus <diod...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Please submit the code that isn''t working. > > On Aug 29, 9:22 am, junkmate <junkm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I have a websitehttp://www.kanjimyblog.comwhichallows clients to > > include random Japanese characters on their blog or homepage. It is > > working fine with a PHP include which serves Javascript to the page, > > and is reasonably quick... > > > Here lies the problem. Due to the nature of <script src=''...''></ > > script> includes, the page only renders once the external file has > > completed loading. So if the client puts the file on his left sidebar, > > the entire page hangs until my script has completed... Even if this is > > only a second, its a second too long... > > > So I want to do this with AJAX or something similar, but cant get it > > working.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You might want to look at Brent Ashley''s JSRS technique. He appends a javasscript tag to the page that points to the URL of your choice. This was an early Ajax technique before libraries like Prototype wrapped XHR nicely. Using this method you could delay firing your javascript load. http://www.ashleyit.com/rs/ On Aug 30, 8:27 am, junkmate <junkm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Its not so much the code isnt working, its the idea. > > Internet browsers do not allow XMLHttp requests across different > domains, due to security risks, so that rules that out. I also tried > using an innerHTML update using the Javascript code setTimeout(script > to run, 0) - which works great on all browsers apart from IE5, which > crashes the browser when you revisit the page... > > Here is the code from the second example: > > CLIENT INCLUDES THIS ON THEIR EXTERNAL PAGE: > <script type="text/javascript"> > (function(){document.write(''<div id="unique_id"></div><p>''); > s=document.createElement(''script''); > s.type="text/javascript"; > s.src="http://url_to_php_scrpt.php"; > setTimeout("document.getElementById(''unique_id'').appendChild(s)",0);}) > () > </script> > > ABOVE SCRIPT CALLS THIS PHP SCRIPT: > document.getElementById(''unique_id'').innerHTML > +=''data_that_I_want_to_display''; > > This works great on all browsers, but it crashes IE if the same page > is re-visited without a refresh... > > On Aug 29, 3:11 pm, Diodeus <diod...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Please submit the code that isn''t working. > > > On Aug 29, 9:22 am, junkmate <junkm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I have a websitehttp://www.kanjimyblog.comwhichallowsclients to > > > include random Japanese characters on their blog or homepage. It is > > > working fine with a PHP include which serves Javascript to the page, > > > and is reasonably quick... > > > > Here lies the problem. Due to the nature of <script src=''...''></ > > > script> includes, the page only renders once the external file has > > > completed loading. So if the client puts the file on his left sidebar, > > > the entire page hangs until my script has completed... Even if this is > > > only a second, its a second too long... > > > > So I want to do this with AJAX or something similar, but cant get it > > > working.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---