Skip to content

Instantly share code, notes, and snippets.

@vote539
Last active December 20, 2015 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vote539/6047372 to your computer and use it in GitHub Desktop.
Save vote539/6047372 to your computer and use it in GitHub Desktop.
Sends data from your Sencha Touch or Ext JS proxy to your server using traditional POST variables (instead of JSON or XML).
/*
Send data to the server as POST parameters. Refer to the documentation for {@link Ext.data.writer.Json}
for more details on proxy writers. Use "urlencode" as the writer type. For example, your store might
look something like this:
Ext.define('App.store.ExampleStore', {
extend: 'Ext.data.Store',
requires: [
'App.model.ExampleModel'
],
config: {
autoLoad: true,
model: 'App.model.ExampleModel',
storeId: 'StudentScores',
proxy: {
type: 'rest',
url: 'example.php',
reader: {
type: 'json'
},
writer: {
type: 'urlencode'
}
}
}
});
*/
/* Copyright 2013 Shane Carr
* Origin: https://gist.github.com/vote539/6047372
* Based on: http://docs.sencha.com/touch/2.2.1/source/Json2.html
* Released under the X11/MIT License. */
Ext.define("Ext.data.writer.UrlEncode", {
extend: "Ext.data.writer.Writer",
alternateClassName: "Ext.data.JsonWriter",
alias: "writer.urlencode",
config: {
allowSingle: true
},
writeRecords: function(request, data){
var params = request.getParams(),
allowSingle = this.getAllowSingle();
if (!data || !(data.length || (allowSingle && Ext.isObject(data)))) {
return request;
}
if (allowSingle && data && data.length === 1) {
data = data[0];
}
request.setParams(Ext.apply(data, params || {}));
return request;
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment