diff --git a/README.md b/README.md
index d7d35db1..6203b030 100644
--- a/README.md
+++ b/README.md
@@ -23,6 +23,7 @@ A form input builder and validator for React JS
- [onInvalid()](#oninvalid)
- [Formsy.Mixin](#formsymixin)
- [name](#name)
+ - [value](#value)
- [validations](#validations)
- [validationError](#validationerror)
- [required](#required)
@@ -246,6 +247,12 @@ Whenever the form becomes invalid the "onInvalid" handler is called. Use it to f
```
The name is required to register the form input component in the form.
+#### value
+```html
+
+```
+You should always use the **getValue()** method inside your formsy form element. To pass a default value, use the value attribute.
+
#### validations
```html
diff --git a/src/main.js b/src/main.js
index 12029214..1bb417a6 100644
--- a/src/main.js
+++ b/src/main.js
@@ -64,10 +64,15 @@ var request = function (method, url, data, contentType, headers) {
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
- if (xhr.status >= 200 && xhr.status < 300) {
- resolve(xhr.responseText ? JSON.parse(xhr.responseText) : null);
- } else {
- reject(xhr.responseText ? JSON.parse(xhr.responseText) : null);
+ try {
+ var response = xhr.responseText ? JSON.parse(xhr.responseText) : null;
+ if (xhr.status >= 200 && xhr.status < 300) {
+ resolve(response);
+ } else {
+ reject(response);
+ }
+ } catch (e) {
+ reject(e);
}
}
@@ -221,7 +226,7 @@ Formsy.Form = React.createClass({
this.props.onSubmit();
- var headers = (Object.keys(this.props.headers).length && this.props.headers) || options.headers;
+ var headers = (Object.keys(this.props.headers).length && this.props.headers) || options.headers || {};
ajax[this.props.method || 'post'](this.props.url, this.model, this.props.contentType || options.contentType || 'json', headers)
.then(function (response) {