Home:ALL Converter>Success not being returned from ajax post

Success not being returned from ajax post

Ask Time:2015-10-31T18:36:59         Author:c-sharp-and-swiftui-devni

Json Formatter

AJAX Post is not returning success call in wordpress. I have the following code and I can get to the first dialog box in testing, but no mater what I do its not getting to the second. It's not finding the function in functions.php even though I have it declared.

    jQuery(document).ready(function(){
    jQuery("#send_btn").click(function(){

    var datastring = $("#redemmpointsForm").serialize();

      var points = $('#points').val();
      var comments = $('#comments').val();

          jQuery.ajax({
             type : "post",
             dataType : "json",
             url : myAjax.ajaxurl,
             data : {"action": "redeempoints", "points":points},
             success: function(response) {
                if(response.type == "success") {
                 alert('do i get here');
                }
                else {
                   // Do something else
                }
             }
          });
    });
     }); //Modal event Ends

functions.php file

wp_localize_script( 'inkthemes', 'MyAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php')));

function functionRedeempoints() {

die();
return true;
}

add_action("wp_ajax_functionRedeempoints", "functionRedeempoints");
add_action("wp_ajax_nopriv_functionRedeempoints", "functionRedeempoints");

Ok so i treid the following

jQuery(document).ready(function(){
jQuery("#send_btn").click(function(){

var points = jQuery('#points').val();
var comments = jQuery('#comments').val();

         var allData = {
   action: 'functionRedeempoints',
   points: points,
   comments:comments
}
       var data = JSON.stringify(allData);   

           alert( data);

          jQuery.ajax({
             type : "post",
             dataType : 'json',
             url : myAjax.ajaxurl,
             data : data,
             success: function(response) {
            if(response.success) {
             alert('do i get here');
            }
            else {
               // Do something else
            }
         }
      });
});
 }); //Modal event Ends

And iN MY FUCNTIONS php Its like its not fidning the php function.

  wp_localize_script( 'inkthemes', 'MyAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php')));

function functionRedeempoints() {
wp_send_json_success(true);
}

add_action("wp_ajax_redeempoints", "functionRedeempoints");
add_action("wp_ajax_nopriv_redeempoints", "functionRedeempoints");

Author:c-sharp-and-swiftui-devni,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/33450594/success-not-being-returned-from-ajax-post
yy