-
5 Dec 2012 2:24 AM #1
Unanswered: How to refactor Ext.Ajax.request to Ext.Model.save
Unanswered: How to refactor Ext.Ajax.request to Ext.Model.save
Hi,
I have the following code:
And I want to refactor this by using model.save, here's the model:Code:assignModel: function(model, date, callback) { var credentials = Ext.getStore('credentialsStore').first(); Ext.Ajax.request({ url: MyApp.Save, params: { username: credentials.get('username'), password: "", token: credentials.get('token'), ApiKey: MyApp.apiKey, date: Ext.Date.format(date, 'Y-m-d'), modelId: model.get('id') }, success: function () { Ext.callback(callback.success); }, failure: function () { Ext.callback(callback.failure, null, ["Failed to assign model"]); } }); }
When I do the first method, I get a clean POST-request with all the params.Code:Ext.define('MyApp.Model', { extend: 'Ext.data.Model', config: { idProperty: 'id', fields: [ { name: 'id', mapping: 'Id', type: 'string' }, { name: 'name', mapping: 'Name', type: 'string' } ], proxy: { type: 'rest', url : MyApp.Save, actionMethods: { create : 'POST', update : 'POST', } } } });
When I do the model.save() method, I get an OPTION and a POST-request with the JSON-object somewhere in it.
How can I alter the save method from the model, so it sends the (username, password, token,...) parameters too? Why are there 2 requests being sent?
-
7 Dec 2012 6:45 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,107
- Vote Rating
- 453
- Answers
- 3155
If you get an OPTIONS request first, that is the browser checking the server to see if it supports CORS.
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.
-
7 Dec 2012 7:14 AM #3
I see. But the request is still being sent wrong, I sent a JSON-object now with model.save() but I need to send a request like the one in the picture.
Most importantly: I don't get the username, token, apiKey parameters which are necessary for the back-end-request.
This is what the server expects:
Attachment 40644
So what do I have to do for the model.save() to work like this?
-
7 Dec 2012 7:25 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,107
- Vote Rating
- 453
- Answers
- 3155
when you do a model.save() are you passing in the params or have them as extraParams on the proxy?
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.
-
7 Dec 2012 7:46 AM #5
I now have them as extraParams, however they get sent in the queryString. Here's how the model.save() request looks:
Screen Shot 2012-12-07 at 16.43.23.png
So they're not in the "Request Payload", and there's no "Form Data"-entry with the Model-parameters. It's just the JSON-object, and the server isn't expecting that.


Reply With Quote