-
16 Apr 2012 9:40 AM #1
Answered: Is a JSON writer what I need?
Answered: Is a JSON writer what I need?
I am working on an app that interfaces with a SharePoint list. Currently I am able to write to the list, using a jQuery $.ajax method, which I don't want to do, because I know there is a way to do the same thing using Sencha Touch. Here is my working code.
This is a submit button, that when fired, grabs my form values, puts it in JSON format, and sends it to the server using and jQuery ajax 'post' method. So my question is do I call a JSON writer in my store, or is there a better way. Below is my store. I have the JSON writer, but i'm not currently using it.Code:xtype: 'button', text: 'Submit', handler: function() { var TextToSubmit = JSON.stringify(Ext.getCmp('SubmitATopicFormPanel').getValues(), null, 2); alert(TextToSubmit); $.ajax({ type: "POST", url: "myURL", data: TextToSubmit, contentType: "application/json; charset=utf-8", error: function(xhr) { alert(xhr.status + ':' + xhr.statusText); } }); } }
Code:Ext.define('TopicApp.store.SafetyStore', { extend: 'Ext.data.Store', id: 'SafetyStore', config: { autoLoad: true, model: 'TopicApp.model.SafetyModel', proxy: { type: 'ajax', url: "myURL", reader: { type: 'xml', record: 'properties' }, writer: { type: 'json' } } } });
-
Best Answer Posted by mitchellsimoens
If you are editing records in a store then the writer can be used. If you are just wanting to send some parameters to the server then you can use Ext.Ajax.request then.
-
16 Apr 2012 10:12 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,666
- Vote Rating
- 435
- Answers
- 3109
If you are editing records in a store then the writer can be used. If you are just wanting to send some parameters to the server then you can use Ext.Ajax.request then.
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.
-
16 Apr 2012 12:04 PM #3
for others,
Code:xtype: 'button', text: 'Submit', handler: function() { var form = Ext.getCmp('SubmitATopicFormPanel'); var TextToSubmit = JSON.stringify(Ext.getCmp('SubmitATopicFormPanel').getValues(), null, 2); Ext.Ajax.request({ url: "myURL", method: 'POST', headers: { "Content-Type": "application/json" }, params: TextToSubmit, success: function (response){ Ext.Msg.alert('Success', 'Your Topic Has Been Submitted!'); Ext.getCmp('MainPanel').animateActiveItem(0, {type:'slide', direction: 'right'}); form.reset(); }, failure: function () { Ext.Msg.alert('Error', 'Error'); } }); }


Reply With Quote