Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for POST requests on the importer #191

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/importers/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* extract - a method to pass raw data through before handing back to parser.
* dataType - ajax datatype
* jsonp - true if it's a jsonp request, false otherwise.
* type - wether to do a post or a get request (defaults to 'GET')
* postData - The post data to send with the request
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change the name of this property to 'data' which is consistent with the parameter types used in jQuery (and thus are well known.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

*/
Dataset.Importers.Remote = function(options) {
options = options || {};
Expand All @@ -20,11 +22,18 @@

// Default ajax request parameters
this.params = {
type : "GET",
type : "GET", // if you define type, otherwise "get"
url : _.isFunction(this._url) ? _.bind(this._url, this) : this._url,
dataType : options.dataType ? options.dataType : (options.jsonp ? "jsonp" : "json"),
callback : options.callback
};

// support for POST requests, just define them here.
if (options.hasOwnProperty('postData') && options.hasOwnProperty('type')) {
this.params.type = options.type;
this.params.data = options.postData;
}

};

_.extend(Dataset.Importers.Remote.prototype, Dataset.Importers.prototype, {
Expand Down