1

I am new to ext js. I am trying to pass a JSON in the request body to service call. I am using the following code to send JSON in the request. I getting an error response when i do so.

Ext.define('MyStore.store.dashboard.graphs.Temp', {
extend: 'Ext.data.Store',
     proxy: {
            type: 'ajax',
            url: 'abc.php', 

            headers: {
                'Content-Type': 'application/json'
            },

           params :  JSON.stringify({
                locationID: [],
                startDtTime: "2009-06-10T11:00:00",
                endDtTime: "2016-05-10T11:00:00",                   
                GroupValue:"",
            }) })

But when i use Ext.Ajax.request i get a proper response:

Ext.Ajax.request({

url: 'abc.php',  

jsonData : data, 

success: function(hxr) {
    console.log(hxr);    
},

failure: function(hxr) {
    console.log(hxr);      
}})

I have seen similar posts in the forums. My question is if there is no way to set json in a request using store then can i pass response obtained from Ext.Ajax.request to my store?

5
  • That's not how the store works, you have to pass your params via store.load({params:{}}); Commented May 27, 2016 at 10:01
  • I am not sure how that is done. Could you explain how do i integrate that with my code? Commented May 27, 2016 at 10:05
  • Without more information about what have you done so far, i don't think so. What version are you using of ExtJS? You are using controllers, viewControllers or where did you execute the code you post? Commented May 27, 2016 at 10:10
  • I am using ext js 6. At the moment i have not written any controllers or view controllers. I am just trying to understand this as i need to build a prototype later. I have just used ext js chart where i fill a graph based on the values in the store. This worked fine when i load it using a static JSON file. But now i need to send certain parameters in a request as a JSON to a server to get a response for my graph. Commented May 27, 2016 at 10:18
  • have you try to add record and then sync? Commented May 29, 2016 at 13:54

1 Answer 1

2

ExtJS always sends POST values as JSON, except when you submit a form with a file upload field.

But ExtJS store uses GET method for read by default, while Ext.Ajax.request uses POST by default if parameters are defined.

But you can explicitly tell the store's proxy to use the POST method:

proxy:{
    actionMethods:{
        read:'POST'
    },
    extraParams : {
        locationID: [],
        startDtTime: "2009-06-10T11:00:00",
        endDtTime: "2016-05-10T11:00:00",                   
        GroupValue:"",
    }
}
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you. I have tried that but it still doesnt work. I have checked chromes developer console and it sends a post request which is fine but doesn't show any value in the request's body.
@NullPointer Sorry, my fault, it's extraParams for store proxy, I have updated the code.
That doesn't seem to work as well. although now i happen to see some text like '0=%7B&1=%22&2=l&3=o&4=c&5=a' in request payload
Thanks.But I need these parameters to be passed as a JSON object, and in the body of the post request

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.