我在做一件事 http
我的请求 angular2+
数据库中存在的代码 node.js
文件。这个 ajax
来自的呼叫 angular2+
点击 controller.js
文件,然后重定向到 service.js
与数据库有连接的文件:
angular.ts ==> controller.js ==> service.js
从数据库 service.js
文件将输出给 controller.js
然后回答问题 ajax
呼叫 angular.ts
文件:
service.js ==> controller.js ==> angular.ts
但是,我得到了一个错误:
POST http://localhost:8096/dashboard/abcEntireSuccess1/ 404 (Not Found)
更新后无法获取/dashboard/experianentResusccess1/
还有一个问题-
UnauthorizedError: No authorization token was found
还有一个问题-
从service.js中的hit返回后,其中包含我想要==>到=>controller.js的数据,这里获取的数据是未定义的。如下所示-
nodejs上的输出-
输出-
服务.js
closed connection
yessss [ RowDataPacket { ....
控制器.js
we are coming back to controller undefined
some error occured of abcEntireSuccess1
我的全部代码:已更新
.component.ts公司
viewAbcEntireSuccess1() {
var url = config.url;
var port = config.port;
this.http.post("http://" + url + ":" + port + "/dashboard
/abcEntireSuccess1/", this.emptyObj
, { headers: new Headers({ 'Authorization': 'Bearer ' +
localStorage.getItem('Token') }) })
.map(resultConnection => this.resultConnection =
resultConnection.json(), )
.subscribe((res: Response) => {
this.records = res;
this.resultConnectionlength = this.resultConnection.length;
});
}
.controller.js公司
router.post('/experianEntireSuccess1',experianEntireSuccess1);
module.exports = router;
function abcEntireSuccess1(req, res) {
dashboardService.abcEntireSuccess1(req.body)
.then(function (result) {
console.log("we are coming back to controller",result)
if (result.length > 0) {
console.log("we get data in node of abcEntireSuccess1 ::
" + Object.values(result));
console.log(result.length + " record found ");
res.send(result);
}
else {
result=[];
res.send(result);
}
})
.catch(function (err) {
res.status(400).send(err);
console.log("some error occured of abcEntireSuccess1");
});
}
.service.js公司
async function abcEntireSuccess1() {
console.log("function called")
const db = new Database();
await db.query(`select * from TRANSACTION_PAYLOAD where INTERFACE_NAME
= 'Abc' AND (STATUS ='SUCCESS_RESPONSE')`
).then(rows => {
console.log("closed connection");
console.log("yessss",rows)
return rows;
});
};
class Database {
constructor() {
this.connection = mysql.createConnection({
host: "127.0.0.1",
user: "abc",
password: "abc",
database: "DB"
});
}
query(sql, args) {
console.log("sql is", sql)
return new Promise((resolve, reject) => {
this.connection.query(sql, (err, rows) => {
console.log("connection function called")
if (err) {
console.log("error is", err)
return reject(err);
}
console.log("rows are",rows);
resolve(rows);
});
});
}
close() {
console.log("calling connection close")
return new Promise((resolve, reject) => {
console.log("called connection close")
this.connection.end(err => {
if (err){
return reject(err);
}
resolve();
});
});
}
}
暂无答案!
目前还没有任何答案,快来回答吧!