How to use or implement rest api using JavaScript ajax

   
var form = new FormData();
form.append("id", "4");

var settings = {
  "url": "https://xxxxxxx.com/api/get-aaaaaaa-by-id",
  "method": "POST",
  "timeout": 0,
  "headers": {
    "Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9..JYoGEVLKvXt42cY42_a6LJ5a1rD4V1fKhbnSfawpBo2nA8l4UJWxXL7KIhPaPjktbFWTKRhuQjQ62xFeQ95AlgxX5t6PGbSWEzZth3Q1BB2roA1nxMK-hG9uAx3PbHzRAD7tmqP9DPSC4GkGSv1yOnLKhbP0sgTlyPp9VM2sYCwqCrF8Z2_dWJWWUIoNRJ_WZ9A-hi29OIn4kgqrE3hJC04qL002CG4QWGstxZqg_yHLKjlfiiJ7msb9Qz8y89gp8V551PYlu8kqz12VtNJGlb8N4aR9RDKa7j16tpavRc7FmOAgvlVajznLlpVpSxM0TX48waZ43h-H_vI28XDuqR0lR2eRslMaa7oTjEEP_Ppyu1cGE8qqzAMwIIC_BEIT1rNiXvTwWSuKjBtjKnkcuwdstq8cCkRwboMKr8iqiz_i7draFp6trXQfCN78yL5Xsh0RYgKUS6_JHk2muMSKv_qeR-jGxjJ0kgq-A03IhHsmnR0FHCyvT4uPYRXC6ELoWGCXgK6Tdi5Dibn1NamQa3IIGbeBPgj7GFxAt8PtuRQikyo6jTgyVtbdL7p8ADLZh4xAV4Mnd2BRcT2JbBhVDqDcNCdxeO15HbXSsAZCaqjy4Yeuma1hJjhJ_58hahhz8YKHsSAtJkjcloDcI3SyJXrac0i5NaeZqg-Bj4uTuW8",
    "Accept": "application/json",
    
  },
  "processData": false,
  "mimeType": "multipart/form-data",
  "contentType": false,
  "data": form
};

$.ajax(settings).done(function (response) {
 // console.log(response);
  const obj = JSON.parse(response);
  var calReminder = obj['data']['calReminder'];
  console.log(obj['data']['calReminder']);
  for(i in  calReminder)
  {
     console.log(calReminder[i]['id']); 
  }
});

$(document).ready(function(){
                $(document).ajaxSuccess(function(){
                    console.log("AJAX request successfully completed.");
                });
                $(document).ajaxError(function (event, jqxhr, settings) {
                    console.log("AJAX error.");
                    if (settings.url == "https://xxxxxx.com/api/get-ddddddd-by-id") {
         
                    }
                });  
                
            });
</script>

Disabling “Use Socket For PHP-FPM” did the trick.


Leave a Reply