1.后端

//处理json数组中文问题
function arrayRecursive(&$array, $function, $apply_to_keys_also = false)
{
static $recursive_counter = 0;
if (++$recursive_counter > 1000) {
die('possible deep recursion attack');
}
foreach ($array as $key => $value) {
if (is_array($value)) {
arrayRecursive($array[$key], $function, $apply_to_keys_also);
} else {
$array[$key] = $function($value);
}
if ($apply_to_keys_also && is_string($key)) {
$new_key = $function($key);
if ($new_key != $key) {
$array[$new_key] = $array[$key];
unset($array[$key]);
}
}
}
$recursive_counter--;
}
//直接返回json数组
function JSON($array) {
arrayRecursive($array, 'urlencode', true);
$json = json_encode($array);
return urldecode($json);
}
//调用
$data = array();
$data['success']="false";
$data['message']="用户名不存在,请重新输入"; echo JSON($data);

2.前端

$.post("ajax.php?mod=member&code=check_user_exist",{username:username},function(data){
var json=$.parseJSON(data);
if(json.success){
alert(json.success);
}else{
alert(json.success);
}
});

php返回json数组的更多相关文章

  1. ajax返回json数组遍历添加到html

    大致需求为类型限制根据类型获取不同结果列表,再根据模糊查询搜索出结果,效果如下:

  2. 返回json数组的GET接口

    Action() { web_reg_find("Search=Body", "SaveCount=find_cnt", "Text=code\&qu ...

  3. jquery ajax调用返回json格式数据处理

    Ajax请求默认的都是异步的 如果想同步 async设置为false就可以(默认是true) var html = $.ajax({ url: "some.php", async: ...

  4. dbda封装类(包括:返回二维数组、Ajax调用返回字符串、Ajax调用返回JSON)

    <?php class DBDA { public $host = "localhost"; public $uid = "root"; public $ ...

  5. js循环处理后台返回的json数组

    <script type="text/javascript"> function gongdan_search(elm){ var dangqian_value=$(e ...

  6. Node.js 使用jQuery取得Nodejs http服务端返回的JSON数组示例

    server.js代码: // 内置http模块,提供了http服务器和客户端功能(path模块也是内置模块,而mime是附加模块) var http=require("http" ...

  7. Jquery 处理返回的 Json 数组

    Jquery 处理返回的 Json 数组 <script> for (var i = 0; i < photos.length; ++ i) { console.log(photos ...

  8. js处理ajax返回的json数组

    一.json对象和json数组的区别 jsonObject = {} # json对象 jsonArray=[{},{}] # json数组 二.数据处理 前台接收到后台传过来的json数组实际上是一 ...

  9. 当返回值为json字符串时 如何获得其中的json数组

    json数据格式 {"IPPORT":"192.168.0.12","time":"2017-04-05 09:12:06&quo ...

随机推荐

  1. JQM弹出对话框

    <div data-role="page" id="pageone"> <div data-role="header"&g ...

  2. docker和shipyard使用问题

    http://blog.csdn.net/cuisongliu/article/details/49178461 Docker启动如果随服务一起启动? docker run -ti -d --rest ...

  3. System.out.println与System.err.println的区别(输出顺序!!!)

    System.out.println与System.err.println的区别(输出顺序!!!) 分类:java (208)  (0) System.out.println与System.err.p ...

  4. Media Wiki

    https://www.mediawiki.org/wiki/Help:Images/zh https://www.mediawiki.org/wiki/Manual_talk:Image_admin ...

  5. gradle 默认属性

    Properties(未翻译) Property Description allprojects 包含该项目及其子项目的属性 ant The AntBuilder for this project. ...

  6. 存储过程中的when others then 和 raise

    EXCEPTION when others then rollback; dbms_output.put_line('code:' || sqlcode); dbms_output.put_line( ...

  7. [工具]json转类

    摘要 这周在园子看到一篇介绍JsonCSharpClassGenerator这个工具的文章,感觉挺实用的,在现在项目中json用的是最多的,所以在转换对应的类的时候,确实挺频繁,所以就研究了一下这个工 ...

  8. 如何快速有效的修改java的环境变量

    之前已经修改过jdk的环境变量,,,,在/etc/profile下,,, export JAVA_HOME=/usr/java/jdk1.7.0_67-cloudera export PATH=${J ...

  9. 密码学初级教程(六)数字签名 Digital Signature

    密码学家工具箱中的6个重要的工具: 对称密码 公钥密码 单向散列函数 消息认证码 数字签名 伪随机数生成器 提问: 有了消息认证码为什么还要有数字签名? 因为消息认证码无法防止否认.消息认证码可以识别 ...

  10. Error: [ng:areq] Argument 'xxxx' is not a function, got undefined

    "Error: [ng:areq] Argument 'keywords' is not a function, got undefined" 代码类似这样的: <div n ...