Raza Ahmed
Raza Ahmed

Reputation: 2751

How to return static JSON from PHP to extjs store

I've a json string, i want to get it in grid store of extjs by a php url. how to return this string as a json from a php file. something like this:

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
});

I know there are methods to return json from php, but they create and then return json. I already have json..

*JSON String : *

{"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":""}]}

Upvotes: 3

Views: 2269

Answers (1)

Lloyd
Lloyd

Reputation: 29668

The simplest solution is to just return the string directly to the response (and set content type of course):

<?php

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

print $my_json_string;

?>

Upvotes: 2

Related Questions