vijay kumar
vijay kumar

Reputation: 377

How to display the json message from ajax call

How to display the message from ajax call which is type of object

$(document).ready(function(){
  $('#checkme').on('click', function () {
    //$('#checkme').attr('disabled',true); 
    $.ajax({
      type: "POST",
      url: '../api/api.php',
      data: $('#tmdt').serialize(),
      dataType: "JSON",
      success: function(response) {
        $("#idv").html();
      }
    });
  });
});
$return_msg = array('response'=>array('status'=>"Transaction type is not valid"));

enter image description here

Upvotes: 1

Views: 2036

Answers (2)

Rick
Rick

Reputation: 711

Update your front end to..

success: function (response) {
    console.log(response);
    $("#idv").html(response.response.status);
}

Update your backend code to:

$return_msg = array('response'=>array('status'=>"Transaction type is not valid"));

echo json_encode($return_msg);

Upvotes: 0

Rory McCrossan
Rory McCrossan

Reputation: 337600

Given the format of the returned JSON you can use response.status, like this:

success: function(data) {
  $("#idv").html(data.response.status);
}

Note that if the returned string does not contain HTML, then you can use the text() method instead of html().

Upvotes: 1

Related Questions