Issue with iron-ajax request
Posted By: Anonymous
I have the following Web API method:
[Route("api/ConfAccount/ByToken")]
public conf_account GetByToken(string token)
{
conf_accountDAO dao = new conf_accountDAO();
try
{
string tokenJson = Crypto.DecryptStringAES(token, "S1gn2s2f3!");
if (tokenJson != null)
{
Token myToken = Newtonsoft.Json.JsonConvert.DeserializeObject(tokenJson) as Token;
var obj = dao.GetObjectByUser(myToken.name);
if (obj != null)
{
return obj as conf_account;
}
else
{
return null;
}
}
else
{
return null;
}
}
catch {
return null;
}
}
I tried to make a request from a Polymer web application, I have an element that call this method but I don’t find a way to configure correctly the iron-ajax object to call this method:
Element
<dom-module id="my-welcome">
<template>
<style>
:host {
display: block;
}
.div-general{
@apply(--layout-horizontal);
width: 100%;
height: 40px;
vertical-align: middle;
display: table-cell;
}
.span-center-middle{
vertical-align: middle;
}
</style>
<iron-ajax
verbose
url="http://192.168.0.16/SignaSafePro/api/ConfAccount/ByToken?"
method='GET'
params = '{{token}}'
headers='{"Accept": "application/json"}'
handle-as="json"
content-type="application/json"
on-response="handleResponse"
debounce-duration="300"
id='ajaxWelcomeElement'>
</iron-ajax>
<iron-localstorage name="my-signasafe-storage" id="localStorage_id" auto-save-disabled useRaw></iron-localstorage>
<div class="div-general">
<paper-icon-button icon="account-circle" id="icon_account"></paper-icon-button>
<span class="span-center-middle">{{welcome_text}}</span>
</div>
</template>
<script>
Polymer({
is: 'my-welcome',
properties: {
conf_account: {
type: Object,
notify: true
},
welcome_text:{
type: String,
notify: true
},
token:{
type: String,
notify: true
}
},
ready: function() {
var localstorage = this.$$('#localStorage_id');
localstorage.reload();
var tokenAux = localstorage.value;
this.token = tokenAux;
var obj = this.$$('#ajaxWelcomeElement');
if(this.token != null){
obj.generateRequest();
}else{
this.welcome_text = 'Welcome Guest';
}
},
handleResponse: function(request){
var result = request.detail.response;
if(result.ResultObject != null){
this.conf_account = result.ResultObject;
if(this.conf_account != null){
this.welcome_text = 'Welcome ' + this.conf_account.conf_account_name;
}else{
this.welcome_text = 'Welcome Guest';
}
}
}
});
</script>
I’m getting the Url Request in the console:
I don’t know why the url get that way because the url suppose to be:
GET api/ConfAccount/ByToken?token={token}
Please I really appreciate any help on this.
Note:
The error that I’m getting is the Error: 404
Solution
I solved the problem changing the iron-ajax element in this way:
<iron-ajax
verbose
url="http://192.168.0.16/SignaSafePro/api/ConfAccount/ByToken?token={{token}}"
method='GET'
handle-as = "json"
content-type = 'application/json'
on-response="handleResponse"
debounce-duration="300"
id='ajaxWelcomeElement'>
</iron-ajax>
Thanks
Answered By: Anonymous
Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.