Access to returned Json single value from controller

by Andrea Suriani   Last Updated May 21, 2020 23:10 PM

i don't understand how to access to a single value returned after ajax call datatype JSON.

My controller returned to me this value:

    {
    name: Andrea
    catname: Minnie
}

How can i acces it from Ajax call response and do some check? My Script is below

jQuery(document).ready(function($) {

$("#avanti").click(function(){

$.ajax({
  type: "POST",
  url: 'index.php?option=com_doclf_users&task=checkcodicefiscale&format=json',
  data: {
      'name_check' : 1,

  },
dataType: "JSON",



  success: function(response){
  // I'd like something like
  if (response.name == 'Andrea')
  {
      $('#name').val(response.name); 
  } else {
   //something else   
  }

  },
  error: function()
  {
    $("#risultato").html('Errore durante l\'esecuzione della funzione');
  }
});

});

Unroftunately it doesn't work....

Can you explain to me how to get access on it?



Related Questions




Error decoding JSON data: Syntax error

Updated July 08, 2018 20:10 PM