0

When i click the button,am calling a function it will return some values.I need to get those values and send through AJAX using Jquery.

Give below the click button function.Inside this function am calling another function(here returning values i need to pass through ajax)

The problem is i cant able to send those values inside ajax.

Can anyone plz help me to do this?I dont know where am doing mistakes.

Here is the function am calling inside button click

13
  • 1
    Return values from which function ?
    – Abdes
    Aug 25, 2019 at 20:53
  • @Abdessamad Plz check my updated code..I have added function
    – numuki sdf
    Aug 25, 2019 at 20:57
  • @Abdessamad my aim is to send dates in one array and frequency in another array..then i can save to database table(two columns are date and frequency)
    – numuki sdf
    Aug 25, 2019 at 20:58
  • @Abdessamad For example if results are 12 rows then database rows will be 12rows this will save when button click or ajax call
    – numuki sdf
    Aug 25, 2019 at 21:05
  • @Abdessamad sir any idea about my question?
    – numuki sdf
    Aug 25, 2019 at 21:13

1 Answer 1

0

in this eaxample i have send with the ajax request the name of the function that i want to use

let fd = new FormData();
fd.append('function_name', 'activity_submitted');


$.ajax({
    url: "activity_submitted.php",
    type: "POST",
    data: fd,
    complete: function (results) {
        try {
            var str = JSON.parse(results.responseText);
        }
        catch (e) {

        }});

in the PHP file (according to the $_REQUETS['function_name']) go to your function, the function will echo a JSON with the values that you want to send back

$_REQUEST is a super global variable which is widely used to collect data after submitting html forms.

           function activity_submitted() {
            .
            .
            .
            $res = array('articleid'=>$articleid);
           $resBack = (json_encode($res, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
           echo ($resBack); 


          }


        ?>
6
  • I have updated my controller function in php.Is that correct?
    – numuki sdf
    Aug 25, 2019 at 21:34
  • activity_submitted is a function not page..function loading are correct only
    – numuki sdf
    Aug 25, 2019 at 21:36
  • sir, in your code where u r calling my function??where u r getting function return values???this is my function saveschedule()
    – numuki sdf
    Aug 25, 2019 at 21:39
  • i dont need these values getcontractbranch_name, getcontractbranch_freq.I need values returning from the FUNCTION only...plz check jsfiddle..there i have mentioned returning values
    – numuki sdf
    Aug 25, 2019 at 21:52
  • i will try to help again dear friend :) Aug 26, 2019 at 7:55

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.