1. #1
    Sencha User
    Join Date
    Jul 2012
    Posts
    35
    Vote Rating
    0
    manoveg is on a distinguished road

      0  

    Default Unanswered: problem using ajax proxy

    Unanswered: problem using ajax proxy


    Hi
    I am new to sencha. Please help.

    I have to create a nested list & I have a api in php which returns data in heirarchical order. I have to write proxy for that.

    I tried
    Code:
      new  Ext.data.Store({
        model: 'kategorieModel',
        autoLoad: true,
        storeid:'kategorieStore',
        proxy: {
            type: 'ajax',
            url: 'myurl',
            extraParams:{request:'offers_list'},
                	limitParam: '',
                	noCache: false,
                	useNull: true,
        	headers: {
            	'Content-Type': 'application/x-www-form-urlencoded'
        	},
    	        reader	: {
        		type	: 'json',
        		encode	: 'false',
        		root	: 'kategorie_name',
    	       }
    }    
    });
    and my model
    Code:
    Ext.regModel('kategorieModel', {
        fields: [
            {name: 'kategorie_name', type:'string'}
        ]});
    but it's not working. I am not getting any response.

    I have an already existing working request for this api which I have to use .

    Code:
    $.ajax({
    			  url: 'myurl',
    			  type:'POST',
    			  data:{ request:'offers_list', params:{}},
    			  success: function(data) {
    			  	var json = eval('('+data+')');
    			  	 addDataToStore(json);
    		 }
    		});
    This is returning json data in required heirarchical order

    please help me create a nested list using the info above. Can I directly use the second $.ajax given and add it to treestore and a nestedlist. If yes please help me with a small code sample . I am not able to get it work

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,582
    Vote Rating
    434
    Answers
    3102
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    What is being returned?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    http://www.JSONPLint.com - Source to lint your JSONP!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Jul 2012
    Posts
    35
    Vote Rating
    0
    manoveg is on a distinguished road

      0  

    Default


    Hi,

    I am getting following error messages
    XMLHttpRequest cannot load <myurl>. Request header field X-Requested-With is not allowed by Access-Control-Allow-Headers.

    I modified the code to
    Code:
    var store = new  Ext.data.TreeStore({
        autoLoad: true,
        storeid:'myapp.stores.kategorieStore123',
        model:'myapp.models.kategory',
        proxy: {
            type: 'scripttag',
            url: 'myurl',
                    limitParam: '',
                    noCache: false,
                    useNull: true,
                    callbackParam:'error_code:0',
                    callbackPrefix:'',
                    model:'myapp.models.kategory',
                    scriptIdPrefix:'',
                    writer:'json',
            headers: {
                'Content-Type': 'Content-Type: application/x-json'
            },
                reader    : {
                type    : 'json',
                encode    : 'false',
                root    : 'output'
               }
    } 
      
    });
    now I am getting following error message:
    Uncaught SyntaxError: Unexpected token : api:1
    and when I click on api:1 I get the exact output that is returned by the api.
    it is like this below

    {"error_code":0,"error_message":"","output":{"Urlaub & Reisen":[{"id":"33770","name":" A&O HOTELS und HOSTELS","beschreib.......


    It appears it is objecting to error_code":0 . But I have a jquery request to the same api & it works fine with this data as output.

    I cannot modify anything at server end so I have to handle whatever it is in my call from sencha touch.
    Please help