博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
jquery,php之间的ajax关系以及json
阅读量:6507 次
发布时间:2019-06-24

本文共 3897 字,大约阅读时间需要 12 分钟。

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':24}

 

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":"30","cat_id":"266","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":"10","goods_number":"5004","price":"65.00","goods_thumb":"images\/201604\/thumb_img\/30_thumb_G_1461895713329.jpg","is_real":"1","is_on_sale":"1","is_alone_sale":"1","is_shipping":"1","add_time":"1456538997","sort_order":"100","is_delete":"0","is_best":"1","is_new":"0","is_hot":"0","is_promote":"0","last_update":"1464541057","is_check":null,"barcode":"8809471951116"},{
"goods_id":"33","cat_id":"203","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":"10","goods_number":"2005","price":"84.00","goods_thumb":"images\/201604\/thumb_img\/33_thumb_G_1461895784860.jpg","is_real":"1","is_on_sale":"1","is_alone_sale":"1","is_shipping":"1","add_time":"1456538997","sort_order":"100","is_delete":"0","is_best":"0","is_new":"0","is_hot":"0","is_promote":"0","last_update":"1464115989","is_check":null,"barcode":"8809091729942"},{
"goods_id":"34","cat_id":"203","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":"10","goods_number":"2005","price":"84.00","goods_thumb":"images\/201604\/thumb_img\/34_thumb_G_1461895812866.jpg","is_real":"1","is_on_sale":"1","is_alone_sale":"1","is_shipping":"1","add_time":"1456538997","sort_order":"100","is_delete":"0","is_best":"0","is_new":"0","is_hot":"0","is_promote":"0","last_update":"1464115989","is_check":null,"barcode":"8809091729966"},{
"goods_id":"35","cat_id":"203","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":"10","goods_number":"2005","price":"85.00","goods_thumb":"images\/201603\/thumb_img\/35_thumb_G_1458064454764.jpg","is_real":"1","is_on_sale":"1","is_alone_sale":"1","is_shipping":"1","add_time":"1456538997","sort_order":"100","is_delete":"0","is_best":"1","is_new":"0","is_hot":"0","is_promote":"0","last_update":"1464115989","is_check":null,"barcode":"8809471950546"}]

js代码

json个数: (html.length)

$.ajax({        url:"{:U('pur/SerAjaxGoods')}",        type: 'GET',        data:{
'keywords':$keywords}, dataType: "json", success:function (html){ $str = '
'; $str +='
'; for(i=0;i
'; $str +='
'; $str +='
'; $str +='
'; } $str +='
'+html[i]['goods_name']+' '+html[i]['goods_sn']+' '+html[i]['goods_barcode']+'
' $('.sel_goods').html($str); //alert(html[0]['goods_id']); }, error:function(){ $str = '
'; $str += '
'; $str +='
'; $str += '
'; $str +='
查询出错,请重新
' $('.sel_goods').html($str); } })

 

转载地址:http://iiwfo.baihongyu.com/

你可能感兴趣的文章
06-验证码-基本功能实现
查看>>
Java数据结构与算法(六) 希尔排序
查看>>
canvas学习笔记
查看>>
IntelliJ Idea下Go项目开启Debug调试
查看>>
elasticsearch安装步骤
查看>>
PHP获取Cookie模拟登录CURL(转)
查看>>
PHP-权限控制类(转)
查看>>
CSS3秘笈第三版涵盖HTML5学习笔记9~12章
查看>>
bzoj1044木棍分割
查看>>
leetcode-136-Single Number
查看>>
微信小程序笔记<五> 页面管理及生命周期(route)——getCurrentPages()
查看>>
http服务器小项目
查看>>
JS案例:Jq中的fadeOut和fadeIn实现简单轮播(没完善,简单实现)
查看>>
一些数学上的名词及操作
查看>>
C# DataGridVie利用model特性动态加载列
查看>>
IPv6 地址分类
查看>>
<%@ include %>指令和<jsp:include>区别
查看>>
因为文件组 'PRIMARY' 已满 解决办法
查看>>
Flume 读取实时更新的日志文件
查看>>
HDU 2049
查看>>