function * getData(){
var callback = function * (data,err) {
if(err){
yield err;
}
if(data){
yield data;
}
};
var x = $.ajax({
url: 'http://localhost:9001/mydata',
success: callback
});
}
var d = getData();
Find more questions by tags JavaScript
You can show the right decision? - tracey commented on July 9th 19 at 11:29
async(function *() {
try {
var result1 = $.ajax("request1");
var result2 = $.ajax("request2");
var result3 = $.ajax("request3");
// Process the result
let results = {"1": yield result1, "2": yield result2, "3": yield result3}
console.log(results);
} catch(xhr) {
console.log("Error:" + xhr);
}
});
Somewhere like this, I write from the phone can't check. - Mortimer commented on July 9th 19 at 11:32
{
if(data)
{
yield data;
} else {
// Then return an error. Or even the first couple may not be.
Check. If anything, we will continue to look. - Mortimer commented on July 9th 19 at 11:38
But also not it! - tracey commented on July 9th 19 at 11:41