PDA

View Full Version : Combobox request to jsonreader



Greg_S
10 Sep 2009, 12:02 AM
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.


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

Greg_S
10 Sep 2009, 12:34 AM
I realised that I had not added

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:


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

Greg_S
10 Sep 2009, 12:57 AM
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:

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


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

milanche
20 Sep 2009, 11:30 PM
Hi.
I see you had a problem and that you solve it.
I have similar problem too.

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:

echo 'stcCallback1002({"result": [{"title":"Test search result", "summary":"its a test
so nothing to display", "searchterm":"test", "id":1}]});';?

Thsnks

Greg_S
21 Sep 2009, 12:45 AM
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