ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[TOC] ##promise解决回调地域 ``` <input type="text" placeholder="你的名字"> <button>搜索</button> <h1></h1> <img src="" alt=""> <p></p> ``` ``` <script> var baseUrl = "https://douban.uieee.com/v2/movie/" function http(url) { return new Promise((resolve, reject) => { $.ajax({ url: baseUrl + url, dataType: "jsonp", success: res => { resolve(res) }, error: err => { reject(err) } }) }) } $("button").click(function () { var value = $("input").val(); http(`search?q=${value}&count=1`).then(res => { var title = res.title; var imgUrl = res.subjects[0].images.small; var id = res.subjects[0].id; $("h1").html(title); $("img").attr("src", imgUrl) return http(id) }).then(res => { var summary = res.summary; $("p").html(summary) }) }) </script> ```