2 added 1259 characters in body
source | link

You don't need to do this part $tradesList = '["' . implode( '","', $trades ) . '"]'; json_encode converts array to json.

EDIT:

php code

function get_my_suggestions() {
  // This function should query the database and get results as an array of rows:
  // GET the recieved data: 'term' (what has been typed by the user)
  $term = $_GET['term'];
  $trades = array('gadha', 'chagol', 'patha');
  //$tradesList = '["' . implode( '","', $trades ) . '"]';

  // echo JSON to page  and exit.
  $response = $_GET["callback"]."(". json_encode($trades) .")";
  echo $response;
  exit;
}
add_action( 'wp_ajax_myajax-submit', 'get_my_suggestions' );

javascript

$(document).ready(function() {
$(".main-search-field").autocomplete({
source: function( request, response ) {  
        jQuery.getJSON( MyAjax_object.ajaxurl + "?callback=?&action=myajax-submit", request, function( data ) {
            response( jQuery.map( data, function( item ) {
                jQuery.each( item, function( i, val ) {
                    val.label = val; // the generated array form get_terms do not have a key so pass val to label
                } );
                return item;
            } ) );
        } );  
    }, 
    minLength: 1,
    appendTo: ".search-container"
}); 

});

You don't need to do this part $tradesList = '["' . implode( '","', $trades ) . '"]'; json_encode converts array to json.

You don't need to do this part $tradesList = '["' . implode( '","', $trades ) . '"]'; json_encode converts array to json.

EDIT:

php code

function get_my_suggestions() {
  // This function should query the database and get results as an array of rows:
  // GET the recieved data: 'term' (what has been typed by the user)
  $term = $_GET['term'];
  $trades = array('gadha', 'chagol', 'patha');
  //$tradesList = '["' . implode( '","', $trades ) . '"]';

  // echo JSON to page  and exit.
  $response = $_GET["callback"]."(". json_encode($trades) .")";
  echo $response;
  exit;
}
add_action( 'wp_ajax_myajax-submit', 'get_my_suggestions' );

javascript

$(document).ready(function() {
$(".main-search-field").autocomplete({
source: function( request, response ) {  
        jQuery.getJSON( MyAjax_object.ajaxurl + "?callback=?&action=myajax-submit", request, function( data ) {
            response( jQuery.map( data, function( item ) {
                jQuery.each( item, function( i, val ) {
                    val.label = val; // the generated array form get_terms do not have a key so pass val to label
                } );
                return item;
            } ) );
        } );  
    }, 
    minLength: 1,
    appendTo: ".search-container"
}); 

});

1
source | link

You don't need to do this part $tradesList = '["' . implode( '","', $trades ) . '"]'; json_encode converts array to json.