Reputation: 785
I'm trying to get the values of some paper-radio-buttons and then pass them to a URL using core ajax. I'm having a hard time knowing if I am getting the values correctly and if I'm passing them to the URL.
When I get the button press:
<paper-button affirmative hover on-tap="{{addNewGraph}}">Submit</paper-button>
I call the following script:
<script>
Polymer("add-graphItem",{
addNewGraph: function () {
var HeaderName = this.$.graphOptionsLoad.$.headerValue.selectedItem.label;
var FunctionName = this.$.graphFunctionsLoad.$.functionValue.selectedItem.label;
console.log("The options are " +HeaderName +" and " +FunctionName);
this.$.sendOptions.go();
console.log(sendOptions);
},
})
</script>
To use core-ajax I'm using:
<core-ajax auto url="/getGraph" method="POST" id="sendOptions"></core-ajax>
The console.log(sendOptions);
throws me "Uncaught ReferenceError: sendOptions is not defined"
Wondering what I'm doing wrong and if anyone has any advice - thanks
Here's a plunker (http://plnkr.co/edit/WPN3vG8LaKjuWyc0omrp?p=preview) that more or less replicates what I'm trying to do
Upvotes: 0
Views: 143
Reputation: 1229
To ensure the ajax is really posts you should write target script on the server side, which can simply reply the incoming request. Then you should add event listener to core-response, see https://www.polymer-project.org/docs/elements/core-elements.html#core-ajax for details.
There is no params definition in the outgoing request in Plunker code. It can be done like this:
Polymer("add-graphItem", {
addNewGraph: function () {
var params = {};
if (this.$.graphOptionsLoad.$.headerValue.selectedItem) {
params['HeaderName'] = this.$.graphOptionsLoad.$.headerValue.selectedItem.label;
}
if (this.$.graphFunctionsLoad.$.functionValue.selectedItem) {
params['FunctionName'] = this.$.graphFunctionsLoad.$.functionValue.selectedItem.label;
}
this.$.sendOptions.params = JSON.stringify(params);
this.$.sendOptions.go();
console.log(params);
},
});
Upvotes: 1