Using the post method on polymer

13 views
Skip to first unread message

105...@students.wits.ac.za

unread,
Jun 17, 2017, 5:57:32 AM6/17/17
to Polymer
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.


Reply all
Reply to author
Forward
0 new messages