php数组ajax json数组对象,php – Ajax Response Json打印结果表或div数组

我有一个php文件的ajax调用,它将数组编码为json数组/对象.我想要做的是将json响应打印成表格式或数组

div的.我坚持如何处理ajax成功的响应.这是我的ajax ..

$(document).ready(function(){

$("#adapter").keyup(function()

{

var adapter = $(this).val();

var dataString = 'searchword='+ adapter +'&format=json' ;

if(adapter=='' || adapter < 2 )

{

$("#display3").hide('');

}

else

{

$.ajax({

type: "POST",

url: "ajax/phpfile",

data: dataString,

cache: false,

success: function(data)

{

var myObj = data;

///NOT how to print the result and decode in html or php///

}

});

}return false;

});

});

这是从服务器返回的json响应.我可以提醒整个json响应,所以我知道它正在ajax方面工作……

{"Result":[{"ptos":{"PTOMasterID":"1","PTOMasterPart":"828B-U6805-L1CX","PTOSeriesUniqueID":"22","PTOPrice":"2715.78","PTOSeries":"82","PTOMounting":"8B","PTOTransmission":"U68","PTOSpeed":"05","PTOShifter":"L","PTOAssemblyID":"1","PTOShaftID":"C","PTOSpecialFeature":"X","PTODate":"2011-11-30 17:28:10"}},{"ptos":{"PTOMasterID":"2","PTOMasterPart":"828B-U6805-L3CX","PTOSeriesUniqueID":"22","PTOPrice":"2715.78","PTOSeries":"82","PTOMounting":"8B","PTOTransmission":"U68","PTOSpeed":"05","PTOShifter":"L","PTOAssemblyID":"3","PTOShaftID":"C","PTOSpecialFeature":"X","PTODate":"2011-11-30 17:28:10"}]}

解决方法:

$(document).ready(function(){

$("#adapter").keyup(function()

{

var adapter = $(this).val();

var dataString = 'searchword='+ adapter +'&format=json' ;

if(adapter=='' || adapter < 2 )

{

$("#display3").hide('');

}

else

{

$.ajax({

type: "POST",

dataType: "json", //set this to json

url: "ajax/phpfile",

data: dataString,

cache: false,

success: function(data)

{

var myObj = data;

///NOT how to print the result and decode in html or php///

console.log(myObj); //to see the object

}

});

}return false;

});

});

或者你可以像这样使用JSON2.js

JSON.parse(text, reviver)

标签:jquery,json,php,ajax

来源: https://codeday.me/bug/20190709/1417453.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值