jquery,php之间的ajax关系以及json
1.最简介写法
function AjaxDepotGoods(id){
$.ajax({
url:"{:U('stock/depot_goods')}",
success:function(html){
$('#depot_goods').html(html)
}
});
}
2.进阶写法
$.ajax({
url:"{:U('pur/SerAjaxGoods')}",
type: 'GET',
data:{'keywords':$keywords},
success:function (html){alert(html);
},
error:function(){
alert('查询错误')
}
})
3.json返回数据
php 输出代码
{'name':'twobin','age':}
js代码
$.ajax({
url:"{:U('pur/SerAjaxGoods')}",
type: 'GET',
data:{'keywords':$keywords},
dataType: "json",
success:function ({
alert(html.name);
})
4.【高级json】php,ajax,json 返回的json是多维数组
php输出的代码
[{"goods_id":"","cat_id":"","goods_sn":"AHC-625","goods_name":"\u97e9\u56fd AHC B5 \u9ad8\u6548\u6c34\u5408\u8212\u7f13\u4fdd\u6e7f\u6d17\u9762\u5976\uff08\u5347\u7ea7\u7248\uff09","brand_id":"","goods_number":"","price":"65.00","goods_thumb":"images\/201604\/thumb_img\/30_thumb_G_1461895713329.jpg","is_real":"","is_on_sale":"","is_alone_sale":"","is_shipping":"","add_time":"","sort_order":"","is_delete":"","is_best":"","is_new":"","is_hot":"","is_promote":"","last_update":"","is_check":null,"barcode":""},{"goods_id":"","cat_id":"","goods_sn":"AHC-605","goods_name":"\u97e9\u56fd AHC \u9ad8\u6d53\u5ea6\u7ef4C\u9ad8\u6548\u51fb\u6591\u51dd\u767d\u9762\u819c\u5347\u7ea7\u7248","brand_id":"","goods_number":"","price":"84.00","goods_thumb":"images\/201604\/thumb_img\/33_thumb_G_1461895784860.jpg","is_real":"","is_on_sale":"","is_alone_sale":"","is_shipping":"","add_time":"","sort_order":"","is_delete":"","is_best":"","is_new":"","is_hot":"","is_promote":"","last_update":"","is_check":null,"barcode":""},{"goods_id":"","cat_id":"","goods_sn":"AHC-606","goods_name":"\u97e9\u56fd AHC \u9ad8\u6d53\u5ea6PCG\u80f6\u539f\u86cb\u767d\u7d27\u80a4\u9762\u819c\u5347\u7ea7\u7248","brand_id":"","goods_number":"","price":"84.00","goods_thumb":"images\/201604\/thumb_img\/34_thumb_G_1461895812866.jpg","is_real":"","is_on_sale":"","is_alone_sale":"","is_shipping":"","add_time":"","sort_order":"","is_delete":"","is_best":"","is_new":"","is_hot":"","is_promote":"","last_update":"","is_check":null,"barcode":""},{"goods_id":"","cat_id":"","goods_sn":"AHC-607","goods_name":"\u97e9\u56fd AHC \u9ad8\u6d53\u5ea6B5\u6c34\u5408\u900f\u660e\u8d28\u9178\u9762\u819c\u5347\u7ea7\u7248","brand_id":"","goods_number":"","price":"85.00","goods_thumb":"images\/201603\/thumb_img\/35_thumb_G_1458064454764.jpg","is_real":"","is_on_sale":"","is_alone_sale":"","is_shipping":"","add_time":"","sort_order":"","is_delete":"","is_best":"","is_new":"","is_hot":"","is_promote":"","last_update":"","is_check":null,"barcode":""}]
js代码
json个数: (html.length)
$.ajax({
url:"{:U('pur/SerAjaxGoods')}",
type: 'GET',
data:{'keywords':$keywords},
dataType: "json",
success:function (html){
$str = '<table width="100%" border="0" cellspacing="0" cellpadding="0" class="tab">';
for(i=;i<html.length;i++){
$str += '<tr>';
$str +='<td>'+html[i]['goods_id']+'</td>';
$str +='<td>'+html[i]['goods_name']+'</td>';
$str +='<td>'+html[i]['goods_sn']+'</td>';
$str +='<td>'+html[i]['goods_barcode']+'</td>';
$str +='</tr>';
}
$str +='</table>'
$('.sel_goods').html($str);
//alert(html[0]['goods_id']);
},
error:function(){
$str = '<table width="100%" border="0" cellspacing="0" cellpadding="0" class="tab">';
$str += '<tr colspan="4">';
$str +='<td align="center"><strong>查询出错,请重新</strong></td>';
$str += '</tr>';
$str +='</table>'
$('.sel_goods').html($str);
}
})
jquery,php之间的ajax关系以及json的更多相关文章
- 使用jQuery发送POST,Ajax请求返回JSON格式数据
问题: 使用jQuery POST提交数据到PHP文件, PHP返回的json_encode后的数组数据,但jQuery接收到的数据不能解析为JSON对象,而是字符串{"code" ...
- jquery通过ajax方法获取json数据不执行success
1.jquery通过ajax方法获取json数据不执行success回调 问题描述:jquery通过ajax方法获取json数据不执行success回调方法 问题原因:json格式存在问题或不符合标准 ...
- jquery通过ajax方法获取json数据不执行success回调
问题描述:jquery通过ajax方法获取json数据不执行success回调方法 问题原因:json格式存在问题或不符合标准写法,导致总是执行error回调方法 解决方案:使json格式务必符合下述 ...
- Jquery Ajax方法传递json到action
ajax向后台传入json需要设置option,如下 contentType:'application/json' data:Json.Stringify(jsObj) 后台处理复杂json对象(不知 ...
- jquery ajax调用返回json格式数据处理
Ajax请求默认的都是异步的 如果想同步 async设置为false就可以(默认是true) var html = $.ajax({ url: "some.php", async: ...
- jquery下php与ajax的互传数据(json格式)自我总结
研究了一整天的json数据与ajax的数据传输,现在进行一个小的自我总结,仅供参考 1.关于ajax的认识 $.ajax(),是jquery下包装好的一个函数:参考地址:http://www.w3sc ...
- jQuery ajax读取本地json文件
jQuery ajax读取本地json文件 json文件 { "first":[ {"name":"张三","sex": ...
- JQuery(三)-- AJAX的深入理解以及JQuery的使用
HTTP HTTP http: 超文本传输协议.特点: 简单.快速.灵活.无状态.无连接 URL: 统一资源定位符. 组成:协议名://主机IP:端口号/项目资源地址?传递参数的键值对#锚点 ①ip ...
- 使用 jQuery 调用 ASP.NET AJAX Page Method
文章来源:http://chungle.iteye.com/blog/406054 说到轻量级的客户端通信,我注意到大多数人喜欢使用 ASP.NET AJAX Page Method 多于 ASMX ...
随机推荐
- RHEL7.2和RHEL6.5的配置网络yum源和本地yum源
RHEL7.2配置本地yum源 [root@localhost ~]#monut /dev/sr0 /mnt #挂载光盘 [root@localhost ~]# rm -rf /etc/yu ...
- ajax请求成功后新开窗口window.open()被拦截解决方法
ajax 异步请求成功后需要新开窗口打开 url,使用的是 window.open() 方法,但是很可惜被浏览器给拦截了,怎么解决这个问题呢 问题: 前面开发项目时碰到一个问题,ajax 异步请求 ...
- Linux吃掉我的内存
在Windows下资源管理器查看内存使用的情况,如果使用率达到80%以上,再运行大程序就能感觉到系统不流畅了,因为在内存紧缺的情况下使用交换分区,频繁地从磁盘上换入换出页会极大地影响系统的性能.而当我 ...
- POJ1962Corporative Network[带权并查集]
Corporative Network Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 3945 Accepted: 14 ...
- USACO2.4 The Tamworth Two[模拟]
题目描述 两只牛逃跑到了森林里.农夫John开始用他的专家技术追捕这两头牛.你的任务是模拟他们的行为(牛和John). 追击在10x10的平面网格内进行.一个格子可以是: 一个障碍物, 两头牛(它们总 ...
- Struts2 JQuery UI常用插件
一.什么是插件 ①是遵循一定接口规范编写的程序 ②是原有系统平台功能的扩展和补充 ③只能运行在规定的系统平台下,而不能单独运行 注:由于jQuery插件是基于jQuery脚本库的扩展,所以所有jQue ...
- Nginx编译参数.md
Nginx 介绍 简介 Nginx(发音同engine x)是一个网页服务器,它能反向代理HTTP, HTTPS, SMTP, POP3, IMAP的协议链接,以及一个负载均衡器和一个HTTP缓存. ...
- (原创)JAVA多线程一传统多线程
一,多线程 多线程是提高程序效率,避免资源浪费的很好的解决方案,下面来慢慢的介绍多线程的一些基本知识,而这些是晋级高级不可或缺的一部分 1,Thread类 类实现多线程需要实现Runnable接口,我 ...
- JS实现Observable观察者模式
欢迎讨论与交流 : ) 注 代码参考自——汇智网 RxJS教程 前言 Observable观察者模式令小白笔者眼前一亮.数据生产者(observable)负责生产新鲜的数据,同时在生产完毕后'通知“消 ...
- Learning Roadmap of Robotic Operating System (ROS)
ROS Wiki: http://wiki.ros.org/ Robots Using ROS Textbooks: A Gentle Introduction to ROS Learning ROS ...