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

iron-ajax sends invalid JSON body if it's a string #278

Open
Boscop opened this issue Jun 21, 2017 · 2 comments
Open

iron-ajax sends invalid JSON body if it's a string #278

Boscop opened this issue Jun 21, 2017 · 2 comments

Comments

@Boscop
Copy link

Boscop commented Jun 21, 2017

When I use <iron-ajax> with content-type="application/json" (and method="post") and then I do this:

        this.$.xhr.body = "foo";
        this.$.xhr.generateRequest();

it just sends foo as the body of the request, but it should send "foo".
A string like "foo" is a valid JSON object but foo is not!

@terrak
Copy link

terrak commented Jun 26, 2017

I think your body should be an object :
this.$.xhr.body = {myvar:"foo"};
or
this.$.xhr.body = JSON.stringify( {myvar:"foo"} );

@drix
Copy link

drix commented Jul 21, 2017

you can do

this.$.xhr.body = '"foo"';
this.$.xhr.generateRequest();

Any change to stringify a body string would slow iron-request performance a bit because it would have to check if the string is just a string or a json stringified otherwise:
this.$.xhr.body = JSON.stringify( {myvar:"foo"} );
would generate an invalid outcome.

I vote to this issue be resolved with some info about this behavior been add to the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants