Firstly the javascript you have posted seems to be incorrect - the blocks of code have mismatched {} , ie onException: is not part of the options object literal passed to Ajax.Request - but that might have been copy and pasting problems
- have you confirmed that the ajax response has the a Content-Type: application/json header? - if so have you tried to console.log the xhr.ResponseText - the JSON might be invalid? - "onsuccess" should be "onSuccess" - you are doing a strictly equal test (===), you might consider just checking equal (==) first get it working and then check strict equal and to answer your main question - the onSuccess is a callback function - returning a value is not really something to be done for a callback function - you can set/get other global variables and you should be able to access the variables in the method you have written Let me know if anything doesn't make sense Jason Westbrook | T: 313-799-3770 | jwestbr...@gmail.com On Sun, Dec 9, 2012 at 3:40 PM, Laurent Barre <houpde...@gmail.com> wrote: > Hi, > > I have a function : > > request:function (object) { > var chaine = "var param = {"; > for (var i = 0; i < object.param.length; i++) { > chaine = chaine + "param_" + i + ":" + object.param[i] + "," > } > chaine = chaine.substr(0, (chaine.length - 1)); > chaine = chaine + "};"; > eval(chaine); > new Ajax.Request(object.php, { > method:object.method, > encoding:'UTF-8', > contentType:'application/x-www-form-urlencoded', > parameters:param, > onsucess:function (xhr, json) { > if (json[0].etat === "A") { > result.etat = 'A'; > result.message = json[0].msg; > /* test 2 */ return {result:result}; > alert('ok'); > } > else if (json[0].etat === "S") { > result.etat = 'S'; > result.message = json[0].msg; > } > } > }, > onException:function (xhr, e) { > alert('Exception : ' + e); > }}); > alert(result.etat); > return {result:result}; > } > > first test : if I test, everything works, I have "alert(ok)", but > "alert(result.etat)" is empty. > second test : with test 2 active, return doesn't work. > > I think that Ajax.Request doesn't exchange the parameters between > ajax.request and my request function. > But I don't know how to link them ? > > Best regards. > > > > -- > You received this message because you are subscribed to the Google Groups > "Prototype & script.aculo.us" group. > To post to this group, send email to > prototype-scriptaculous@googlegroups.com. > To unsubscribe from this group, send email to > prototype-scriptaculous+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/prototype-scriptaculous?hl=en. > -- You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.