gpt4 book ai didi

php - 如何从 PHP 返回静态 JSON 到 extjs 存储

转载 作者:行者123 更新时间:2023-12-05 05:27:48 25 4
gpt4 key购买 nike

我有一个 json 字符串,我想通过 php url 在 extjs 的网格存储中获取它。如何从 php 文件中将此字符串作为 json 返回。像这样:

var store = Ext.create('Ext.data.Store', {
id: 'store',
model: 'ForumThread',
remoteGroup: true,
buffered: true,
leadingBufferZone: 300,
pageSize: 100,
proxy: {
type: 'jsonp',
url: 'myJsonPhp.php', //this file should return json.
reader: {
root: 'topics',
totalProperty: 'totalCount'
}},
autoLoad: true
});

我知道有一些方法可以从 php 返回 json,但它们会创建并返回 json。我已经有 json..

*JSON 字符串:*

{"totalCount":"6679","topics":[{"title":"XTemplate with in EditorGridPanel","threadid":"133690","username":"kpr@emco","userid":"272497","dateline":"1305604761","postid":"602876","forumtitle":"Ext 3.x: Help","forumid":"40","replycount":"2","lastpost":"1305857807","excerpt":""},{"title":"IFrame error "_flyweights is undefined"","threadid":"133571","username":"Daz","userid":"52119","dateline":"1305533577","postid":"602456","forumtitle":"Ext 3.x: Help","forumid":"40","replycount":"1","lastpost":"1305857313","excerpt":""},{"title":"Status bar error with IFrames","threadid":"134120","username":"Daz","userid":"52119","dateline":"1305857168","postid":"604220","forumtitle":"Ext 3.x: Bugs","forumid":"41","replycount":"0","lastpost":"1305857168","excerpt":""},{"title":"hellllllllllllllp,why it doesn't fire cellclick event after I change the cell value??","threadid":"133827","username":"aimer311","userid":"162000","dateline":"1305700219","postid":"603309","forumtitle":"Ext 3.x: Help","forumid":"40","replycount":"3","lastpost":"1305856996","excerpt":""},{"title":"Extjs 4.0 support for IE9","threadid":"122352","username":"extdev22","userid":"48017","dateline":"1296097557","postid":"565503","forumtitle":"Ext: Open Discussion","forumid":"6","replycount":"30","lastpost":"1305841535","excerpt":""},{"title":"Using XTemplate to send XML","threadid":"134102","username":"cayenne_08","userid":"237393","dateline":"1305841170","postid":"604153","forumtitle":"Ext 3.x: Help","forumid":"40","replycount":"0","lastpost":"1305841170","excerpt":""},{"title":"Open Source Development - The people you interact with....","threadid":"134093","username":"watrboy00","userid":"9862","dateline":"1305837814","postid":"604114","forumtitle":"Community Discussion","forumid":"68","replycount":"0","lastpost":"1305837814","excerpt":""},{"title":"What widgets are missing most in the ExtJs library?","threadid":"134091","username":"Andrew.Golik","userid":"32056","dateline":"1305837033","postid":"604102","forumtitle":"Community Discussion","forumid":"68","replycount":"0","lastpost":"1305837033","excerpt":""},{"title":"What widgets are missing most in the ExtJs library?","threadid":"134090","username":"Andrew.Golik","userid":"32056","dateline":"1305836975","postid":"604100","forumtitle":"Community Discussion","forumid":"68","replycount":"0","lastpost":"1305836975","excerpt":""},{"title":"What widgets are missing most in the ExtJs library?","threadid":"134089","username":"Andrew.Golik","userid":"32056","dateline":"1305836900","postid":"604099","forumtitle":"Community Discussion","forumid":"68","replycount":"0","lastpost":"1305836900","excerpt":""}]}

最佳答案

最简单的解决方案是直接将字符串返回到响应(当然还要设置内容类型):

<?php

header("Content-Type: application/json");

print $my_json_string;

?>

关于php - 如何从 PHP 返回静态 JSON 到 extjs 存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17273164/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com