First of all, small example: function GetURL() { new Ajax.Request(''/updater.php?GetURL=yes'', { method:''get'', onSuccess: function(transport){ response = transport.responseText; alert(response); } }); } PHP script echo URL, AJAX gets it and response should be and is "http://localhost/forum". So far everything is okay, but I would like GetURL() return that response and I can''t get it out from new Ajax.Request. Let''s say I would write like this: function GetURL() { var response; new Ajax.Request(''/updater.php?GetURL=yes'', { method:''get'', onSuccess: function(transport){ response = transport.responseText; } }); return response; } But it won''t happen ever. response will be set as unidentified. Any ideas how I could make GetURL() to return what I need? P.S. Thanks for your all help. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
onSuccess is a callback function. And where this part of code is perform:> new Ajax.Request(''/updater.php?GetURL=yes'', > { > method:''get'', > onSuccess: function(transport){ > response = transport.responseText; > alert(response); > }your function ISN''T invoke. It''s invoke only when this request is done. Therefore response variable is undefined. 1. Give us more knowledge about a context. (When you need GetURL() function?) 2. If you just want to know current url then you can use window.location.href --~--~---------~--~----~------------~-------~--~----~ 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 have Flash in my website and it has small menu, one of it''s items is forum and after I press it Flash calls JavaScript function GetURL(), which get URL through PHP script and it must return it (it must return string) and Flash captures string which contains new forum URL. It works fine, it gets the URL. But I am stuck inside on Success method:> onSuccess: function(transport){ > response = transport.responseText; > alert(response); > }I need to get that response outside and I could make function to return it (GetURL() must return string with URL). --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Of course, there is a decision. You should just set asynchronous option to ''false'': var getURL = function() { var response; var request = new Ajax.Request(''/updater.php?GetURL=yes'', { method: ''get'', asynchronous: false, /* it''s really bad style */ onSuccess: function(transport) { response = transport.responseText; alert(transport.responseText) } }); return response; } For your information: it''s really horrible and bad method to use AJAX and prototype.js like this code do it. But, I think, it should work like you wanted. I don''t recommend you to use this getURL() function. Maybe it will be better to use ActionScript, or embed url XHTML per PHP (using <?= php_variable ?>). Don''t forget, that you can use PHP not only to generate XHTML. You can use it to generate JavaScript, for example: <script> var getURL = function() { return <? your php code here ?>; } </script> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
This would be the best way for me at least for now. I am no every good in ActionScript, but maybe I am going to study a bit and maybe I will avoid using AJAX for this and make direct call from Fash to PHP script. And I can''t use the second idea, I have only main.js with few hundreds lines of JavaScript code and it''s completely off PHP. Thanks for the help and I am going to read more about "asynchronous" parameter. But I won''t be able to test this today, I am going to sleep. I am going to write a bit later in morning how it worked. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---