Quote: [Unhandled promise rejection: TypeError: (0, _fastXmlParser.parse) is not a function. (In '(0, _fastXmlParser.parse)(data)', '(0, _fastXmlParser.parse)' is undefined)]
import { parse } from 'fast-xml-parser'; function test(){ const emp_number = 20209; fetch('http://website.com/partner/api.php?emp_number='+`${emp_number}`, { method: 'POST', headers: { Accept: 'text/plain', 'Content-Type': 'text/plain' } }) .then((response) => response.text()) .then((data) => { let obj = parse(data); let servicenumber = obj.counter.serviceNumber; let consumpationtype = obj.counter.consumpationtype; let currentread = obj.counter.currentread; let currentdate = obj.counter.currentdate; let lastread = obj.counter.lastread; let lastdate = obj.counter.lastdate; let consumpation = obj.counter.consumpation; console.log("CurrentReading:"+`${currentread}`); });}
<?php header('Content-Type: text/plain'); $gecolEmployee = $_GET['emp_number']; $serverName = "host\SqlS"; $connectionInfo = array( "Database"=>"gecol"); $conn = sqlsrv_connect( $serverName, $connectionInfo); $query = "SELECT * FROM readers WHERE emp_number=?"; $result = sqlsrv_query($conn, $query, array($gecolEmployee)); $row = sqlsrv_fetch_array($result); if( $conn ) { echo $row['xml']; }else{ echo "خطأ.<br />"; die( print_r( sqlsrv_errors(), true)); } ?>
<counter> <serviceNumber>200135644</serviceNumber> <consumpationtype>1</consumpationtype> <currentread>95808</currentread> <currentdate>29/6/2022</currentdate> <lastread>85808</lastread> <lastdate>29/5/2022</lastdate> <consumpation>?</consumpation> <counternumber>7038842</counternumber> <phonenumber>0928065968</phonenumber> </counter>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)