Vote count:
0
I am trying to use Polymer core-ajax element to extract data out of an online API. Checking via developer tool the API request get successful with code 200 and expected XML response is returned. But the response object is null stopping me to proceed.
This is my core element,
<polymer-element name="get-employees" attributes="employeeList">
<template>
<core-ajax id="ajax" auto
url="https://localhost:8443/GetEmployees"
method='POST'
headers='{"X-Token":"4517612052875154027"}'
handleAs='xml'
contentType="application/xml"
response= "{{resp}}"
on-core-complete="{{success}}"
on-core-error="{{errorF}}"
body='<?xml version="1.0" encoding="UTF-8" standalone="no"?><GetEmployees xmlns="http://ift.tt/14dbdmM"><<Employees><Employee><EmployeeNo/><TitleCode/><Initials/> <GivenNames/><Surname/></GetEmployees>'>
</core-ajax>
<template repeat="{{employee in resp | nodeList('Employee') }}" id="tem">
<div class="empcard" flex>
<div>{{employee || nodeText('GivenNames')}} zxcxcx</div>
</div>
</template>
</template>
<script>
Polymer('api-get-employees', {
errorF: function(){
console.log('Error occured');
},
success: function(event, detail, sender){
console.log(event);
},
nodeList: function(element, name) {
var arr;
arr = element ?
[].slice.call(element.querySelectorAll(name)) : ['No Employees for the given query'];
return arr;
},
nodeText: function(element, name) {
return element.querySelector(name).innerHTML;
}
});
</script>
</polymer-element>
The XML returned in in following format
<?xml version="1.0" encoding="UTF-8"?>
<GetEmployeesResponse xmlns="http://ift.tt/14dbdmM">
<APIResponseStatus>
<Code>OK</Code>
</APIResponseStatus>
<Employees>
<Employee>
<EmployeeNo>ISH001</EmployeeNo>
<GivenNames>Omid</GivenNames>
<Initials>OR</Initials>
<Surname>KORDESTANI</Surname>
<TitleCode>Mr</TitleCode>
</Employee>
<Employee>
<EmployeeNo>ISH002</EmployeeNo>
<GivenNames>Gary</GivenNames>
<Initials>GR</Initials>
<Surname>PARANTE</Surname>
<TitleCode>Mr</TitleCode>
</Employee>
</Employees>
</GetEmployeesResponse>
When I debug event or detail objects in success method does not carry the return XML or resp object. The element parameter for nodeList function also returns "No Employees...." message.
Can someone please let me know where I have messed up. I have tried otherthings but none has succeeded so far.
Thanks in advance, Ish
asked 1 min ago
Polymer core-ajax xml response element is null
Aucun commentaire:
Enregistrer un commentaire