扫码关注官方订阅号
大概是这样子:
图片名称 年份 价格 图片名称 年份 价格 图片名称 年份 价格 图片名称 年份 价格
年份
java后台传给我一个接口,我怎么从这个接口里面获取数据,并更新前台li列表呢?
$.ajax(function(){ url:"", method:"", data:"", success:function(){ } })
怎么写呢?可不可以讲得详细点,谢谢。
小伙看你根骨奇佳,潜力无限,来学PHP伐。
<!DOCTYPE html> <html> <head> <title>test</title> </head> <body> <ul></ul> <script src="http://code.jquery.com/jquery-3.1.1.min.js"></script> <script> function fill_ul(){ /* $.ajax(function(){ url:"", method:"", data:"", success:function(response){//这里是后台返回的数据结果 response.data.forEach(function(d){ var space = $('<li><a><img src=""></a><h2>图片名称</h2><p>年份</p><span>价格</span></li>'); space.find('img').attr('src', d.img_url); space.find('h2').text(d.img_name); space.find('p').text(d.year); space.find('span').text(d.price); $('ul').append(space); }) } })*/ var d = {img_url: 'https://img.changker.com/85/af/49/85af492184f6ecc4cffdb5b8e423a07c', img_name: 'img_name', year: 2017, price: 800};//这里假设了你需要循环的对象的结构 var space = $('<li><a><img src=""></a><h2>图片名称</h2><p>年份</p><span>价格</span></li>'); space.find('img').attr('src', d.img_url); space.find('h2').text(d.img_name); space.find('p').text(d.year); space.find('span').text(d.price); $('ul').append(space); } $(document).ready(function(){ fill_ul(); }) </script> </body> </html>
jQuery 把数据拼成html,放到需要放的地方比如1、遍历一下数据,拼成var html = '<li>...</li><li>...</li><li>...</li>';2、<ul id="data"> ul标签加个id$("#data").html(html);
artTemplate 你值得拥有
根据返回的数据,写到html上
jQuery+vue,对付这种东西很简单。但是你应该是刚入门的,可能要过段时间才能用吧。
patrickhai回答的代码是对的。你可以再搜索了解一下ajax和json。就能够简单的明白了。
这个是jquery封装的ajax方法。
ajax, js jquery get() http://www.w3school.com.cn/jq...
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
jQuery
把数据拼成html,放到需要放的地方
比如
1、遍历一下数据,拼成
var html = '<li>...</li><li>...</li><li>...</li>';
2、<ul id="data"> ul标签加个id
$("#data").html(html);
artTemplate 你值得拥有
根据返回的数据,写到html上
jQuery+vue,对付这种东西很简单。但是你应该是刚入门的,可能要过段时间才能用吧。
patrickhai回答的代码是对的。你可以再搜索了解一下ajax和json。就能够简单的明白了。
这个是jquery封装的ajax方法。
ajax, js jquery get() http://www.w3school.com.cn/jq...