user285594
user285594

Reputation:

Syncronous XMLHTTPRequest deprecated crash browser?

I have to read information as below from a microprocessor hardware

var save_it = '';
$.ajax({
    type: "GET",
    url: 'http://www.micro-processor-server/?ROBOT=arm_controle',
    async: false,
    success:function(m) {
      save_it =  m;
    }
  }).responseText;
console.log(save_it);

While doing so, it works, but my browser console gives very scary warning as below, also several times I have noticed web-browser Google chrome get hang:

enter image description here

Can anyone please show an alternative way how to make my Ajax query compatible? (I can't change codes in Micro-processor its third party robot)

Upvotes: 0

Views: 172

Answers (2)

user5405873
user5405873

Reputation:

call another function with return data.

 $.get('http://www.micro-processor-server/?   ROBOT=arm_controle',function(data){
     myfun(data);
 });

 myfun(data){ 
    console.log(data);//here you might be able get rid of asynchronous behaviour.
 }

Upvotes: 0

castletheperson
castletheperson

Reputation: 33466

Put the code that needs the response in the success function. You could also use $.get if this is all you're needing to do.

$.get('http://www.micro-processor-server/?ROBOT=arm_controle', function(data) {
    console.log(data);
});

Upvotes: 1

Related Questions