Return data from function to ajax javascript

jquery ajax return value from success: function
how to return value from ajax success: function in javascript
how to get value from ajax response in javascript
how to increase ajax response time in jquery
how to get return value from ajax call
return ajax response to variable
how to get return value from ajax call in javascript
how to check ajax response in javascript

I wanted to make a button when I clicked it called that ajax function to send data to a function then the function returns the data back to the ajax so that it can execute the success call which makes the button become disabled.

Here's the function notify()

public function notify()
{

    $id = $this->user['id'];

    $agent = AffiliateAgents::get($id);
    if (empty($agent)) redirect('affiliate/sales/browse');

    $_POST = array_map('trim', $_POST);

    $agent = [
        'commission_claim' => 1

    ];

    AffiliateAgents::update($id, $agent);
    $status = AffiliateAgents::get($id ,'commission_claim');

    return $status;
}

Here's the ajax

$("#notify").click(function() {
        $.ajax({
            url: 'affiliate/sales/notify',
            success: function() {
            showNotification("success", "Berjaya!", "Anda berjaya membuat tuntutan komisyen");
        }

    });

    })

just pass parameter into success function in this line: ... success: function(yourData) { ...

How to return data from ajax success function?, In my front end JavaScript application, I make an ajax request to fetch data from the server. As soon as I get the data, I want to return that piece of� Return data from function to ajax javascript I wanted to make a button when I clicked it called that ajax function to send data to a function then the function returns the data back to the ajax so that it can execute the success call which makes the button become disabled. Here's the function notify()

As you wanted to disable the buttons after the success of Ajax. You have to write the following code

in ajax part

    success : function(data){
     // disable button
     if(data="success"){
       $("#buttonId").attr("disabled","disabled");
     } else{
       alert("Status not success");
     }
}

Ajax function to return value - JavaScript, Remove the final return “Hello” and specify an error condition or some other reason why you would want to return something other than the data. function� If you care about developer convenience, you could write your code with async/await. Since jQuery 3.x, $.ajax returns Promises - which is a browser-builtin technology to manage asynchronous code.

You can get the returned data (from PHP) like this:

//In the ajax...
success: function(data) {
      console.log(data)
    }

success Type: Function( Anything data, String textStatus, jqXHR jqXHR ) A function to be called if the request succeeds. The function gets passed three arguments: The data returned from the server, formatted according to the dataType parameter or the dataFilter callback function, if specified; a string describing the status; and the jqXHR (in jQuery 1.4.x, XMLHttpRequest) object. As of jQuery 1.5, the success setting can accept an array of functions. Each function will be called in turn. This is an Ajax Event.

http://api.jquery.com/jquery.ajax/

How to return data after ajax call success, How to return data after ajax call success. Categories Development Tags Ajax Javascript. There are Example object with ajax method var Example = (function () { // ctor function self() { } // Ajax request method self.Request� php,jquery,ajax,json I want to post some data to php function by ajax, then get the encoded json object that the php function will return, then I want to get the information (keys and values) from this object, but I don't know how, here is my code: $.ajax({ url: "functions.php", dataType: "JSON", Merge and sum values and put them in an array

How to Return AJAX Response from Asynchronous JavaScript Call, How to Return AJAX Response from Asynchronous JavaScript Call: Methods In addition to JSON and XML, data can also be transported as plain text. A callback is a function that would give you the result or response you� I have a function that i want to call another function to get a result from the server web page (text format) and return it to the original function this is not working - what am I doing wrong

AJAX & Deferreds, AJAX — "asynchronous JavaScript and XML" — is a means of loading data from a That means that this function's return statement runs before the request is� The server should return valid JavaScript that passes the JSON response into the callback function. $.ajax() will execute the returned JavaScript, calling the JSONP callback function, before passing the JSON object contained in the response to the $.ajax() success handler.

jQuery.ajax(), The server should return valid JavaScript that passes the JSON response into the callback function. $.ajax() will execute the returned JavaScript, calling the JSONP callback function, before passing the JSON object contained in the response to the $.ajax() success handler. Assuming that you have a basic understanding about JavaScript Promises, I’ll start by creating a method which returns a Promise, so that you can see how to return data from promise. function getPromise(){ return new Promise(function(resolve,reject){ setTimeout(function(){ resolve({'country' : 'INDIA'}); },2000) }) }

Comments
  • Is this core PHP or any framework?
  • this is framework sir
  • Please mentioned that framework in the tag that you able to get right answer.
  • sorry sir, i forget to tag framework as well
  • No, my dear name means Laravel or CodeIgniter etc.
  • So if i wanted my function to return the $status data from the function to the ajax i gotta write $status on the success function?
  • no the name of the parameter can be anything just don't put $ inf front of the variable name (since it's javascript). So in your case it could ba name status. You can try to log it out like so: ... success: function(status) { console.log(status) } ...
  • so on the notify() am i doing it correctly in terms of returning back the data to the ajax call?
  • I manage to find out the value of $status by var_dump but it seems that it doesnt return back to the ajax after the whole process end inside the notify() function
  • yes, i can assure the url is correct because when i clicked the button it direct to the function and do operations inside the function where it involve with the database and yes it send the data in the database as well so the URL is functioning
  • So if i wanted my function to return the $status data from the function to the ajax i gotta write $status on the success function?
  • No, just do what I write... the (php) return $status will be given in the function(data), so you can use data inside success
  • Use this console.log(data) to check what's returning.