Home > front end >  Js request information
Js request information

Time:12-14

 
<script>
The function the req () {
$. Ajax ({
Type: "GET",
url: '../Bt. PHP ',
DataType: 'json,
Success: the function (res) {

The console. The log (res [' cpuRealUsed ']);//note

},
Error: function () {
The console. The log (' attempt failed ~ ');
}
});
}
The req ();
SetInterval (the req, 1000);


The function echar () {
//I want here to get the res [' cpuRealUsed] information
}

</script>





A great god please help to give directions!

CodePudding user response:

 
The function echar (res) {
The console. The log (res [' cpuRealUsed ']);//note
}
The function the req () {
$. Ajax ({
Type: "GET",
url: '../Bt. PHP ',
DataType: 'json,
Success: the function (res) {
Echar ()

},
Error: function () {
The console. The log (' attempt failed ~ ');
}
});
}
The req ();
SetInterval (the req, 1000);

This not line?

CodePudding user response:

O
refer to the second floor and pure _ response:
 
The function echar (res) {
The console. The log (res [' cpuRealUsed ']);//note
}
The function the req () {
$. Ajax ({
Type: "GET",
url: '../Bt. PHP ',
DataType: 'json,
Success: the function (res) {
Echar ()

},
Error: function () {
The console. The log (' attempt failed ~ ');
}
});
}
The req ();
SetInterval (the req, 1000);

This not line?
this not line, adjustable don't come out

CodePudding user response:

 
<script>
Var timr=null
The function echar (res) {
The console. The log (res [' cpuRealUsed ']);//note
}

The function the req () {
$. Ajax ({
Type: "GET",
url: '../Bt. PHP ',
DataType: 'json,
Success: the function (res) {
Echar (res)
The init ()
},
Error: function () {
The console. The log (' attempt failed ~ ');
}
});
}
The req ();
The function the init () {
Timr & amp; & ClearTimeout (timr)
Timr=setTimeout (1000) the req,
}
</script>


Don't use the setInterval, if the response timeout, reconnection success leads to accept before stacking all requests for the result

CodePudding user response:

The function the req () {
$. Ajax ({
Type: "GET",
url: '../Bt. PHP ',
DataType: 'json,
Success: the function (res) {
Echar (res)//res passed out, in echar method resolution field you need
The init ()
},
Error: function () {
The console. The log (' attempt failed ~ ');
}
});
}

CodePudding user response:

 & lt; Script> 
Var res=null;
The function the req () {
$. Ajax ({
Type: "GET",
url: '../Bt. PHP ',
DataType: 'json,
Success: the function (res) {
Res=res [' cpuRealUsed];
The console. The log (res [' cpuRealUsed ']);//note

},
Error: function () {
The console. The log (' attempt failed ~ ');
}
});
}
The req ();
SetInterval (the req, 1000);


The function echar () {
//I want here to get the res [' cpuRealUsed] information
console.log(res);
}

</script>


Use var to define a null null object, due to the effect of variables with the ascending of the var definition, so the internal parameter directly, has become a global variables, the parameters can be in any place to visit or call

CodePudding user response:

 
<script>
The function echar (data) {
console.log(data);
}
The function the req () {
$. Ajax ({
Type: "GET",
url: '../Bt. PHP ',
DataType: 'json,
Success: the function (res) {

The console. The log (res [' cpuRealUsed ']);//note
Echar (res [' cpuRealUsed ']);

},
Error: function () {
The console. The log (' attempt failed ~ ');
}
});
}
The req ();
SetInterval (the req, 1000);




</script>
  •  Tags:  
  • Ajax
  • Related