Ajax call of WordPress function

Can someone show me a good example of how to call a PHP function with Ajax? I’m trying to save an image gallery (with dynamic number of images) to database in the admin settings section. The below code is incomplete or maybe with some errors. Please show me a good example or a better way:

Save Changes

function jsAddSettingsFields(){      var elements = document.getElementsByTagName("img");     var urlsdata = new Array();      for (var i = 0, element; element = elements[i++];) {         if (elements[i].id == "idGalPic") {              urlsdata[i] = elements[i].src;  //now we have all image urls in array, now need to call add_settings_fields               var data = {                     action: 'php_addsettingsfields',                     p_urls: urlsdata //I think i need to JSON this                 };              jQuery.post( "", function( data ) );              //https://api.jquery.com/jQuery.post/         }     }  }//end of js function 

//PHP part:

        function php_addsettingsfields_callback() {              $  pic_urls = $  _POST['p_urls'];  //De-JSON-fy this variable              foreach ($  pic_urls as &$  url) {                 add_settings_field($  url);             }         add_settings_field(             'pic_url_id', // ID - slug name of field             '', // Title              array( $  this, 'pic_gal_callback' ), // Callback             'TestPlugin', // Page             'setting_section_id' // Section ID - slug name of page                  );         public function pic_gal_callback()       {            <input type="hidden" id="idPic" name="idPic" value=$  url>          }           //after all hidden fields(with gallery pic urls) are added to setting section submit the page and save the gallery urls to database