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 not posting data #1929

Closed
ahumblenerd opened this issue Jun 20, 2015 · 4 comments
Closed

iron-ajax not posting data #1929

ahumblenerd opened this issue Jun 20, 2015 · 4 comments
Assignees

Comments

@ahumblenerd
Copy link

<dom-module id="my-new-app">
<style>
</style>
<template>

  <iron-ajax
      id="ajax"
      handle-as="json"
      content-type="application/json"
      method="POST"
      body={"user":2,"dob":"2015-06-10","jobs":1,"skills":[],"about":"cool"}
      on-response="hresponse"
      debounce-duration="3000">
  </iron-ajax>
  <button on-click="setajax">Click me</button>
</template>
<script>
Polymer({
  is: "my-new-app",
  setajax: function () {

      this.$.ajax.url="http://127.0.0.1:8000/users/";
    this.$.ajax.generateRequest();
  },
  hresponse: function(request) {
    console.log(request.detail.response);
    console.log(this.$.ajax.lastResponse);
    console.log(this.$.ajax.params);
  }
});
</script>
</dom-module>

This does not post data correctly to the server. Also when i put in a console.log inside the iron-ajax.html file i found out that contentType was still set as application/x-www-form-urlencoded . The documentation says we can specifiy contentype by specifiying contentType = {String}.

@adalinesimonian
Copy link

The body attribute should be wrapped in quotes:

<iron-ajax
  body='{"user":2,"dob":"2015-06-10","jobs":1,"skills":[],"about":"cool"}'
  ...

Other than that, I can't seem to replicate the behaviour you're seeing:

screen shot 2015-06-20 at 1 14 13 pm

Mind providing more details?

@ahumblenerd
Copy link
Author

It works fine when i try to post it to a normal service . But when i try my own backend based on Django Rest Framework it throws out errors . And when i looked into it , Django was receiving application/x-www-form-urlencoded instead of application/json.So I went inside iron-ajax/iron-ajax.html and typed in a console.log() to print all parameters and it was showing that the encoding was not changing even when I was explicitly specifying .
poly

@kevinpschaaf
Copy link
Member

This issue tracker is for the core Polymer library, not elements created with Polymer. We'll get this moved to the right tracker for iron-ajax.

@tjsavage
Copy link
Contributor

This issue was moved to PolymerElements/iron-ajax#66

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

No branches or pull requests

4 participants