0

I used the async-await code in the script file. that script file called using ajax call. when I call ajax URL. it's not waited. it's going next line. this is my problem

MY Scenario

a.html

<script>

function call(){
  r =$.ajax({
      url: "/a/b",
      type: 'POST'
    })
}

$(document).ready(function(){
call()
console.log('hi')
})
</script>

Ajax call code

async function loadcontact(){  

  for(let i=0;i < 3; i++){  
let b = await i;  
console.log(b)  
}
}

Excepted Output

0
1
2
hi

I got output

0
hi
1
2

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
hari prasanth
  • 716
  • 1
  • 15
  • 35

0 Answers0