Home > Backend Development > PHP Tutorial > ajax返回处理

ajax返回处理

WBOY
Release: 2016-06-23 13:48:52
Original
1100 people have browsed it



$.get("pai.php",{bbid:bbid,pid:pid,},function(data){
alert("a:"+data);
                                alert("b:"+data.status);
},"json");
返回值:{"status":1,"info":"\u7ed3\u675f","data":[{"wjc_title":"2\u53a2\u5c0f\u8f7f\u8f66"},{"wjc_title":"3\u53a2\u5c0f\u8f7f\u8f66"}],"jieg":11}
返回值不会处理了,还是对jq不太了解。
我怎么把返回值data里的wjc_title的值插入到div里的li里,有几个wjc_title就循环几个

  • 插入值




  • 插入值1



  • 插入值2





回复讨论(解决方案)

<script type="text/javascript">    var data = {"status":1, "info":"\u7ed3\u675f", "data":[        {"wjc_title":"2\u53a2\u5c0f\u8f7f\u8f66"},        {"wjc_title":"3\u53a2\u5c0f\u8f7f\u8f66"}    ], "jieg":11};    function insert(data) {        if (!jQuery.isArray(data.data)) return false;        var $target = jQuery('div.row').empty();        for (var i = 0; i < data.data.length; ++i) {            $target.append("<ul><li>" + data.data[i].wjc_title + "</li></ul>");        }        return true;    }    insert(data);    </script>
Copy after login
Copy after login

<script type="text/javascript">    var data = {"status":1, "info":"\u7ed3\u675f", "data":[        {"wjc_title":"2\u53a2\u5c0f\u8f7f\u8f66"},        {"wjc_title":"3\u53a2\u5c0f\u8f7f\u8f66"}    ], "jieg":11};    function insert(data) {        if (!jQuery.isArray(data.data)) return false;        var $target = jQuery('div.row').empty();        for (var i = 0; i < data.data.length; ++i) {            $target.append("<ul><li>" + data.data[i].wjc_title + "</li></ul>");        }        return true;    }    insert(data);    </script>
Copy after login
Copy after login


效果没起作用

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html> <head>  <meta http-equiv="content-type" content="text/html; charset=utf-8">  <title> New Document </title>  <script src="//code.jquery.com/jquery-1.11.0.min.js"></script> </head> <body>	<div class="row">		<ul>			<li>插入值1</li>		</ul>		<ul>			<li>插入值2</li>		</ul>	<div>  <script type="text/javascript">    var bbid = 1;    var pid = 1;		$.get("pai.php",{bbid:bbid,pid:pid,},function(data){		for(var i=0; i<data.data.length; i++){			$($('.row').find('li').get(i)).html(data.data[i].wjc_title);		}	},"json");  </script> </body></html>
Copy after login


pai.php
<?phpecho '{"status":1,"info":"\u7ed3\u675f","data":[{"wjc_title":"2\u53a2\u5c0f\u8f7f\u8f66"},{"wjc_title":"3\u53a2\u5c0f\u8f7f\u8f66"}],"jieg":11}';?>
Copy after login

本末倒置!
php 作为服务端,理应按客户端的要求返回数据
你连客户端代码都不会写,那还 ajax 做什么?

本末倒置!
php 作为服务端,理应按客户端的要求返回数据
你连客户端代码都不会写,那还 ajax 做什么?


不是把客户端需求传给服务端,服务处理结果在返给前端显示?
客户端代码和JQ不一样吧!
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template