Results 1 to 3 of 3

Thread: Is a JSON writer what I need?

  1. #1
    Sencha User
    Join Date
    Mar 2012
    Posts
    38
    Vote Rating
    7
      0  

    Default 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.

    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);                                    
                                        }
                                });
    
    
                                }
                        }
    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:
    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'
                        }
                    }
                }
    });

  2. 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.

  3. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,336
    Answers
    3885
    Vote Rating
    1296
      0  

    Default

    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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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 in print!

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

  4. #3
    Sencha User
    Join Date
    Mar 2012
    Posts
    38
    Vote Rating
    7
      0  

    Default

    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');
                             }
                    });
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •