Results 1 to 5 of 5

Thread: Combobox request to jsonreader

  1. #1
    Sencha User
    Join Date
    Sep 2009
    Posts
    9

    Question Combobox request to jsonreader

    Hi,

    I have read through the examples and I have been working from the forum search example on this. At present I have tested the combboox and dataview with locla data and that part works fine.

    I am now trying to access a remote store through the scripttagproxy and jsonreader. However I am using livehttpheaders to check the request to the remote server.

    On making any changes in the combobox it does not submit the query in the URL string. I have setup the default to return a single row with default text to display in the dataview.

    Code:
    var ds = new Ext.data.Store({
            autoLoad:true,
            proxy: new Ext.data.ScriptTagProxy({
            url: 'http://10.168.1.2/rest/searchfront/search.json?',
            method: 'GET'
        }),
        reader: new Ext.data.JsonReader({
        root: "result",
        id: "id",
        },[
            {name:'id'}
            {name:'title'}
            {name:'summary'}
            {name:'searchterm'}
        ])
    });
    
    var resultTpl= new Ext.XTemplate({
        
        //TPL CODE IS DEFINED AND WORKING
    });
        
    
    var search = new Ext.form.ComboBox({
        store: ds,
        displayField:'title',
        typeAhead: false,
        loadingText: 'Searching...',
        width: 570,
        emptyText: 'Enter a search term',
        tpl: resultTpl,
    });
    If I visit the url (http://10.168.1.2/rest/searchfront/search.json?) directly and add 'query=' so url is:
    http://10.168.1.2/rest/searchfront/search.json?query=
    which I think the combobox should add by default the json string is returned in the format
    {"result":[{"title":["No Result"], "summary":["None"], "id":1, "searchterm":""}]}]

    Can anyone tell me why I am not getting the query parameter added to the get string from the store. And will this, once working, query the store each time a new term or text is added to the combobox?

    The combobox is rendered in the center panel of a viewport. The url passes the query string to a python script and returns results in the format shown above.

    Viewing the query to 10.168.1.2 it is in the form of
    /rest/searchfront/search.json?_dc=1252569992345&callback=stcCallback1001

    And using the example I expected the query parameter to be added

    forum/topics-remote.php?query=test&start=0&limit=10&_dc=1252569992345&callback=stcCallback1001

  2. #2
    Sencha User
    Join Date
    Sep 2009
    Posts
    9

    Default

    I realised that I had not added
    Code:
    valueField: 'title',
    Into the combobox.

    However I can see in firebug that data is being returned now, but I am getting an error for invalid label?

    The JSON string returned is:

    Code:
    {"result": [{"title":"Test search result", "summary":"its a test so nothing to display", "searchterm":"test", "id":1}]}

  3. #3
    Sencha User
    Join Date
    Sep 2009
    Posts
    9

    Thumbs up

    I have fixed this issue now.

    Having checked the returned result for scripttagproxy and comments by animal on other threads I realised that I hadnt included the callback with the returned json string.

    instead of:
    Code:
    {"result": [{"title":"Test search result", "summary":"its a test so nothing to display", "searchterm":"test", "id":1}]}
    The callback must also be returned:

    Code:
    stcCallback1002({"result": [{"title":"Test search result", "summary":"its a test
    so nothing to display", "searchterm":"test", "id":1}]});
    It now works and thought would be useful for others to see the solution

  4. #4
    Ext User
    Join Date
    Sep 2009
    Location
    Belgrade, Serbia
    Posts
    7

    Default

    Hi.
    I see you had a problem and that you solve it.
    I have similar problem too.
    Code:
    url: 'http://10.168.1.2/rest/searchfront/search.json?'
    Tel me what type this file is?
    I'm using PHP. And i guess that php should throw some output? or i'm doing wrong...
    If not, how does it look like that output?
    is it:
    Code:
    echo 'stcCallback1002({"result": [{"title":"Test search result", "summary":"its a test
    so nothing to display", "searchterm":"test", "id":1}]});';
    ?

    Thsnks

  5. #5
    Sencha User
    Join Date
    Sep 2009
    Posts
    9

    Default

    Hi,

    I am using python on the django framework.

    All you need do is take the callback parameter passed in the get request and return that in the correct format with the JSON as the result from your script since the callback will change for each request and is passed in the url string as callback=

    HTH

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •