Javascript 回调函数支持ajax

Javascript 回调函数支持ajax,javascript,jquery,Javascript,Jquery,我在使用promise回调显示json中的信息时遇到问题。我已经显示了帖子,但无法显示每个帖子的注释。泰 这是我的密码 JS 如果可以将ES8语法与async await结合使用,请按以下步骤进行操作: 异步函数getHTML{ 常数根https://jsonplaceholder.typicode.com/posts'; const response=await$.getroot; 设html=; 对于设i=0;iconsole.loghtml,err=>console.error; 出于某

我在使用promise回调显示json中的信息时遇到问题。我已经显示了帖子,但无法显示每个帖子的注释。泰

这是我的密码

JS


如果可以将ES8语法与async await结合使用,请按以下步骤进行操作:

异步函数getHTML{ 常数根https://jsonplaceholder.typicode.com/posts'; const response=await$.getroot; 设html=; 对于设i=0;i<10;i++{ html+=JSON.stringifyresponse[i]+; comments=await$.getroot+'/'+i+'/comments'; 对于const comment of comments{ html+=JSON.stringifycomment+; } } 返回html; } getHTML.thenhtml=>console.loghtml,err=>console.error;
出于某种原因,你已经用两种不同的思路问了两次问题。我已经回答了。

为什么不直接使用jQuery成功回调函数呢?避免“完成”和“成功”回调,始终使用“完成”和“成功”回调。这很有效,但我需要使用类似的语法。我不能用你的密码。。这是一个小小的进步,我现在所学的..添加了一个替代方案,它不使用异步或等待,而是`和承诺。所有ES6。这就是我需要的。泰。
var root = 'https://jsonplaceholder.typicode.com/posts'

$.ajax({
    url: root,
    method:'GET',
    data:{
        a:''
    }
})

  .done(function(post) {

      for(i=0 ; i<10;i++){
        document.write(JSON.stringify(post[i]))
        document.write('<br>')
        document.write('<br>')
        document.write('<br>')
      }

  })
 .done(function(comments){
    for(j=0; j<10;j++){
        $.ajax({
          url: root +'/'+ j+'/comments',
          method:'GET',
          comments:{
              b:''
          }

      })
            }

 })