Hie. So i'm new to polymer and I've been having problem when posting. It
returns a null even though the php file returns something. The GET method
works fine though. Here is my code:
The compent:
<template>
<button type="submit" onclick="getPost" class="btn btn-default"
id="register-form" style="margin-left: 35%; background-color: #008000; color:
black; width: 30%;">Submit</button>
<iron-ajax
id="ajax"
method="POST"
body='[{"id": "1"}]'
url ="http://localhost/api/post.php"
on-response="success"
lastError="error"
debounce-duration="3000">
</iron-ajax>
</template>
<script>
Polymer({
is: 'register-form',
getPost:function(){
this.$.ajax.generateRequest();
},
success:function(r){
alert(r.detail.response);
},
error:function(r){
alert(r.detail.response);
}
});
</script>
Enter code here...
The php:
<?php
header('Access-Control-Allow-Origin: *');
if ($_POST){
echo $_POST['id'];
}
?>
Initially I wanted the the php to return a json but it kept on returning
null.So i decided to change it to that to see if it will return the id I
posted but it still returned null. I've tried the solutions i found on the
Internet but it still dint work.Please help.
Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups
"Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/polymer-dev/1d01dca5-fe74-49ac-90fc-f3d1191ef942%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.