synchronous get request JavaScript

How to make a synchronous GET request in JavaScript?

<script>
localStorage.language="calendar_main";
function SignName(sign_id,id){
  var form = new FormData();
  var settings = {
  "url": "/api/api-function/"+sign_id+"/"+localStorage.language+"",
  "method": "GET",
  "timeout": 0,
  "headers": {
    
  },
  "processData": false,
  "mimeType": "multipart/form-data",
  "contentType": false,
  "data": form,
  "async": false,
};

$.get(settings).done(function (response) {
  const obj = JSON.parse(response);
  var sign=obj['data'];
  //console.log(data);
  for(i in sign)
  {
    $("#sign"+id).append(sign[i]['name']);

  }
  
});
}

$(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 == "") {
         
                    }
                });  
                
            });
      
</script>
use async: false in your data

Leave a Reply