Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
add contentType property and default to
Browse files Browse the repository at this point in the history
"application/x-www-form-urlencoded"
  • Loading branch information
frankiefu committed Jan 9, 2014
1 parent e6e5b18 commit 875beb6
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions polymer-ajax.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="polymer-xhr.html">

<polymer-element name="polymer-ajax" attributes="url handleAs auto params response method headers">
<polymer-element name="polymer-ajax" attributes="url handleAs auto params response method headers contentType">
<script>
Polymer('polymer-ajax', {
/**
Expand Down Expand Up @@ -130,6 +130,14 @@
* @default null
*/
body: null,
/**
* Content type to use when sending data.
*
* @attribute contentType
* @type string
* @default 'application/x-www-form-urlencoded'
*/
contentType: 'application/x-www-form-urlencoded',
ready: function() {
this.xhr = document.createElement('polymer-xhr');
},
Expand Down Expand Up @@ -214,10 +222,13 @@
if (args.params && typeof(args.params) == 'string') {
args.params = JSON.parse(args.params);
}
args.headers = this.headers || args.headers;
args.headers = this.headers || args.headers || {};
if (args.headers && typeof(args.headers) == 'string') {
args.headers = JSON.parse(args.headers);
}
if (this.contentType) {
args.headers['content-type'] = this.contentType;
}
args.callback = this.receive.bind(this);
args.url = this.url;
args.method = this.method;
Expand Down

0 comments on commit 875beb6

Please sign in to comment.