當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
json_encode ajaxReturn getJSON
生活随笔
收集整理的這篇文章主要介紹了
json_encode ajaxReturn getJSON
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
之前我在頁面中getJSON("")
$.getJSON("/index.php/Shopcar/getspcar",function(data){
spcars.splist=data;
console.log(data);
});
在訪問的方法中這樣寫的
$this->scres = $sc->query($sql);
$data = json_encode($this->scres);
$this->ajaxReturn($data);
然后在js中的splist賦值不成功。
錯誤原因:ajaxReturn(data),會對data進行編碼,如果是數組的話,會解析成json,json_encode是編碼為字符串,所以這個方法返回時就返回成了字符串。
賦值就沒有成功。spcars.splist[0]=data;這樣就成功了?
轉載于:https://www.cnblogs.com/pigmorn/p/4140536.html
總結
以上是生活随笔為你收集整理的json_encode ajaxReturn getJSON的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SQL点滴19—T-SQL中的透视和逆透
- 下一篇: gradle idea java ssm