solepixel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Mar-16 15:42 UTC
Ajax.Request onSuccess - function with response
Currently I have 2 functions for saving data: function confirmStep2(){ var error_msg = validateForm(''step2''); if(error_msg == ""){ prepareStuff(''Validating your information...''); var poststr = saveString(''step2''); new Ajax.Request(''crossjax.php?step2&validate'', {parameters : poststr, onSuccess : saveStep2, asynchronous : true}); } else { errorStuff(error_msg); } return false; } function saveStep2(t){ var error_msg = validateForm(''step2''); var validate = t.responseText; if(validate.indexOf('' '') != -1){ var error_msg = validate; } if(error_msg == ""){ prepareStuff(''Saving your information...''); var poststr = saveString(''step2''); new Ajax.Request(''crossjax.php?step2'', {parameters : poststr, onSuccess : function(){ goTo(''step3''); }, asynchronous : true}); } else { errorStuff(error_msg); } return false; } The problem is I can''t pass any information onto the next function due to the fact that the onSuccess call of the first function won''t allow me to enter any variables. How can I setup 1 function that will allow me to get a response back and make sure it''s blank and then process the information again without a URL parameter, maybe something like this: function confirmStep2(var_i_need_for_second_step){ var error_msg = validateForm(''step2''); if(error_msg == ""){ prepareStuff(''Validating your information...''); var poststr = saveString(''step2''); new Ajax.Request(''crossjax.php?step2&validate'', {parameters : poststr, onSuccess : handleResponse, asynchronous : true}); handleResponse = function(t) { var validate = t.responseText; if(validate.indexOf('' '') != -1){ var error_msg = validate; } if(error_msg == ""){ prepareStuff(''Saving your information...''); new Ajax.Request(''crossjax.php?step2'', {parameters : poststr, onSuccess : function(){ goTo(var_i_need_for_second_step); }, asynchronous : true}); } } } else { errorStuff(error_msg); } return false; } This would be really helpful because I could then setup 1 function for all my steps, rather than having 1 for each step. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
solepixel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Mar-16 21:04 UTC
Re: Ajax.Request onSuccess - function with response
Ok, I think I figured it out. I may have had it close to right before, but was just missing a } or something. Here is an example: function confirmStep(step_num,goto_step,button_msg){ var error_msg = validateForm(step_num); var opt = { // Send the data parameters: $(step_num).serialize(), // Use asynchronous asynchronous: true, // Handle successful response onSuccess: function(t) { error_msg = validateForm(step_num); var validate = t.responseText; if(validate.indexOf('' '') != -1){ var error_msg = validate; } //alert(validate); if(error_msg == ""){ new Ajax.Request(''crossjax.php?''+step_num, {parameters: $ (step_num).serialize(), onSuccess: function(){ goTo(goto_step); }, asynchronous: true}); } else { errorStuff(button_msg,error_msg); } }, // Handle other errors onFailure: function(t) { alert(''Error: '' + t.status + '' -- '' + t.statusText); } } if(error_msg == ""){ prepareStuff(''Validating your information...''); //var poststr = saveString(''step1''); new Ajax.Request(''crossjax.php?'' + step_num + ''&validate'', opt); } else { errorStuff(button_msg,error_msg); } return false; } On Mar 16, 10:42 am, "solepi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <solepi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Currently I have 2 functions for saving data: > > function confirmStep2(){ > var error_msg = validateForm(''step2''); > > if(error_msg == ""){ > prepareStuff(''Validating your information...''); > var poststr = saveString(''step2''); > new Ajax.Request(''crossjax.php?step2&validate'', {parameters : > poststr, onSuccess : saveStep2, asynchronous : true}); > } else { > errorStuff(error_msg); > } > > return false; > > } > > function saveStep2(t){ > var error_msg = validateForm(''step2''); > > var validate = t.responseText; > if(validate.indexOf('' '') != -1){ > var error_msg = validate; > } > > if(error_msg == ""){ > prepareStuff(''Saving your information...''); > var poststr = saveString(''step2''); > new Ajax.Request(''crossjax.php?step2'', {parameters : poststr, > onSuccess : function(){ goTo(''step3''); }, asynchronous : true}); > } else { > errorStuff(error_msg); > } > return false; > > } > > The problem is I can''t pass any information onto the next function due > to the fact that the onSuccess call of the first function won''t allow > me to enter any variables. > > How can I setup 1 function that will allow me to get a response back > and make sure it''s blank and then process the information again > without a URL parameter, maybe something like this: > > function confirmStep2(var_i_need_for_second_step){ > var error_msg = validateForm(''step2''); > > if(error_msg == ""){ > prepareStuff(''Validating your information...''); > var poststr = saveString(''step2''); > new Ajax.Request(''crossjax.php?step2&validate'', {parameters : > poststr, onSuccess : handleResponse, asynchronous : true}); > > handleResponse = function(t) { > var validate = t.responseText; > if(validate.indexOf('' '') != -1){ > var error_msg = validate; > } > > if(error_msg == ""){ > prepareStuff(''Saving your information...''); > new Ajax.Request(''crossjax.php?step2'', {parameters : poststr, > onSuccess : function(){ goTo(var_i_need_for_second_step); }, > asynchronous : true}); > } > } > } else { > errorStuff(error_msg); > } > > return false; > > } > > This would be really helpful because I could then setup 1 function for > all my steps, rather than having 1 for each step.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Andreas Franke
2007-Mar-17 13:28 UTC
AW: [Rails-spinoffs] Ajax.Request onSuccess - function with response
Hi, If i correctly understood your problem, i had the same a few days ago and this might work for you: ---------------------------------------------------------------------------- function saveStep2(t){ var error_msg = validateForm(''step2''); var validate = t.responseText; if(validate.indexOf('' '') != -1){ var error_msg = validate; } if(error_msg == ""){ prepareStuff(''Saving your information...''); var poststr = saveString(''step2''); new Ajax.Request(''crossjax.php?step2'', {parameters : poststr, onSuccess : function(transport,json){ goTo(transport,json,''step3''); }, asynchronous : true}); } else { errorStuff(error_msg); } return false; } function goTo (transport,json,yourdata){ var response = transport.responseText; alert (yourdata); } ---------------------------------------------------------------------------- Andreas --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Brian DiChiara
2007-Mar-19 19:20 UTC
Re: AW: [Rails-spinoffs] Ajax.Request onSuccess - function with response
Ok, so, what exactly is already available from the xhttp request? I''ve seen transport.responseText, and responseStatus, etc. What all do I have access to. Also, what does the json variable return? On 3/17/07, Andreas Franke <info-8Zvurif+njuzQB+pC5nmwQ@public.gmane.org> wrote:> > > Hi, > If i correctly understood your problem, i had the same a few days ago and > this might work for you: > > ---------------------------------------------------------------------------- > function saveStep2(t){ > var error_msg = validateForm(''step2''); > > var validate = t.responseText; > if(validate.indexOf('' '') != -1){ > var error_msg = validate; > } > > if(error_msg == ""){ > prepareStuff(''Saving your information...''); > var poststr = saveString(''step2''); > new Ajax.Request(''crossjax.php?step2'', {parameters : > poststr, onSuccess : function(transport,json){ > goTo(transport,json,''step3''); > }, asynchronous : true}); > } else { > errorStuff(error_msg); > } > return false; > } > > function goTo (transport,json,yourdata){ > var response = transport.responseText; > alert (yourdata); > } > > ---------------------------------------------------------------------------- > > Andreas > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---