typo3 - Separate the response of a Jquery Post -


I am trying to send a post-request and am different to the response to the callback.

  function get_response () {var data = {value1: "value1", value 2: "value2"}; $ ("/ Index.php? Id = 1", data, function (text) {$ ("# container1") empty (); $ ("# container1") .andend ($); $ ("#container2" ) Empty (); $ ("# container2"). Attachment (text);}); Return; }   

I am currently sending two values ​​to the current page. Each value is passed on to a different function and each function gives me a result.

  if (isset ($ _ POST ['value1'])) {echo $ this-> function_1 (); Go out; } If (isset ($ _ POST ['value2'])) {echo $ this-> Function_2 (); Go out; }   

I have tried to do a lot already and even more than that ... but I can not get anything to fix my condition. I basically want to paste the returns-value of function_1 into # container1 and the return-value of function_2 into # container2.

I think my mind is more confused than the structure of my question .. But I hope that it is still something to understand (

I currently run 2 different post-functions, but as both intervals are set, send me at the same time Having more than one post has trouble, it is in my opinion disabled (the interval is low, so it can be a heap).

why don 'do you add responses and then divide them If (isset ($ _ POST ['value1'])) {$ response = $ this-> function_1 ();} if (isset ($ _ POST ['value2'])) {$ response. '' $. $ This-> function_2 ();} echo $ response;

and in junkery:

  function get_response () {var data = {value1: "value1", value 2: "value2"}; $ .post ("/ index.php? Id = 1", data, function (text) ) {Var response = text.split ("|"); if (response.length == 2) {$ ("# container1") empty (); $ ("# Container1") attached (response [0]). $ ("# Container2") below () .; $ ("# Container2") attached (feedback [1]). }}); Data = null; Text = null; Return; }   

Option 2 will be JSON because @ShubirQumaras says: $ response = Array (); If (isset ($ _ POST ['value1'])) {$ response ['value1'] = $ this- & gt; Function_1 (); } If (isset ($ _ POST ['value2'])) {$ response ['value2'] = $ this- & gt; Function_2 (); } Echo json_encode ($ response);

and JQuery:

  function get_response () {var data = {value1: "value1", value 2: "value2"}; $ .post ("/ index.php? Id = 1", data, function (text) {var response = jQuery.parseJSON (text); if (response.length == 2) {$ ("# container1"). $ ("# Container1"). Add (response.value1); $ ("# container2") empty (); $ ("# container2"). Attachment (response.value2);}}); Data = null; Text = null; Return; }   

You should try as many positions as possible because this performance is expensive.

Comments