AI写作智能体 自主规划任务,支持联网查询和网页读取,多模态高效创作各类分析报告、商业计划、营销方案、教学内容等。 广告
![](https://box.kancloud.cn/f6cc42177ad86926374340993db4ca51_324x454.png) ### ajax `<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>` ~~~ <div id="div"></div> <img src="" alt=""> <script> $.ajax({ type: "get", url: "https://api.douban.com/v2/movie/top250", dataType: "jsonp", success: function (data) { var subjects = data.subjects; console.log(subjects) var title = subjects[0].title; var imgUrl = subjects[0].images.small; $("#div").html(title); $("img").attr("src", imgUrl) } }) </script> ~~~ ### get ~~~ var url="https://douban.uieee.com/v2/movie/top250"; $.get(url,res=>{ console.log(res); var subjects = res.subjects; var data = subjects[0]; var img = data.images.small; var title = data.title; $("img").attr("src",img); $("p").html(title); },"jsonp"); ~~~ ### vue ~~~ <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script> <script src="https://cdn.bootcss.com/vue/2.5.21/vue.js"></script> ~~~ **代码**如下: ~~~ <div id="app"> <p>{{msg}}</p> <img :src="imgUrl" alt=""> </div> <script> var vm = new Vue({ el: "#app", data: { msg: "hello", imgUrl:"" }, //beforeCreate是生命周期函数,相当于小程序里的onLoad,事件写在这里才能触发 beforeCreate() { var url = "https://api.douban.com/v2/movie/top250"; $.get(url,res=>{ this.msg=res.subjects[0].title; this.imgUrl = res.subjects[0].images.small; },"jsonp") } }) </script> ~~~ ### react ~~~ <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>Hello React!</title> <script src="https://cdn.staticfile.org/react/16.4.0/umd/react.development.js"></script> <script src="https://cdn.staticfile.org/react-dom/16.4.0/umd/react-dom.development.js"></script> <script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script> <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script> </head> <body> <div id="example"></div> <script type="text/babel"> class Clock extends React.Component{ constructor(props){ super(props); this.state={ title:"hello world", imgUrl:"" } } render(){ return( <div> <h1>{this.state.title}</h1> <img src={this.state.imgUrl} /> </div> ) } componentDidMount(){ var url = "https://api.douban.com/v2/movie/top250"; $.ajax({ url, type:"get", dataType:"jsonp", success: res=> { /* console.log(res); */ var subjects = res.subjects[0]; var title = subjects.title; var imgUrl = subjects.images.small; this.setState(()=>{ return { title, imgUrl } }) } }) } } ReactDOM.render( <Clock />, document.getElementById('example') ); </script> </body> </html> ~~~