Recipe App Using Node.js & PostgreSQL - Part 6

Recipe App Using Node.js & PostgreSQL - Part 6

Traversy Media

8 лет назад

17,878 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@neala9124
@neala9124 - 01.09.2016 04:11

Nice tuto, i wait for more.!!! XD

Ответить
@jsprjjsprj
@jsprjjsprj - 02.10.2017 10:37

invalid input syntax for integer: "undefined"

"D:\JetBrains\WebStorm 2017.2.3\bin\runnerw.exe" D:\nodejs\node.exe D:\timesheet\app.js
Server started
{ error: invalid input syntax for integer: "undefined"
at Connection.parseE (D:\timesheet\node_modules\pg\lib\connection.js:546:11)
at Connection.parseMessage (D:\timesheet\node_modules\pg\lib\connection.js:371:19)
at Socket.<anonymous> (D:\timesheet\node_modules\pg\lib\connection.js:114:22)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:547:20)
name: 'error',
length: 98,
severity: 'ERROR',
code: '22P02',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'numutils.c',
line: '62',
routine: 'pg_atoi' } undefined
{ error: invalid input syntax for integer: "undefined"
at Connection.parseE (D:\timesheet\node_modules\pg\lib\connection.js:546:11)
at Connection.parseMessage (D:\timesheet\node_modules\pg\lib\connection.js:371:19)
at Socket.<anonymous> (D:\timesheet\node_modules\pg\lib\connection.js:114:22)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:547:20)
name: 'error',
length: 98,
severity: 'ERROR',
code: '22P02',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'numutils.c',
line: '62',
routine: 'pg_atoi' } undefined



Here is the code

app.delete ('/delete/:employee_id', function(req,res){
const text = "DELETE FROM EMPLOYEES WHERE EMPLOYEE_ID=$1"

pool.query(text,[req.params.employee_id], (err, res1) => {
console.log(err, res1);

// pool.end()
});

const client = new Client({
connectionString: connectionString,
})
client.connect()

client.query(text,[req.params.employee_id], (err, res1) => {
console.log(err, res1)
client.end()
res.sendStatus(200);
});



some how values on req.params.employee_id parameter is not getting


Here is the delete.js

$(document).ready(function(){
$('.delete-salary').on('click',function(){
var employee_id = $(this).data('employee_id');
var url = '/delete/'+employee_id;
if(confirm('Delete Recipe?')){
$.ajax({
url: url,
type: 'DELETE',
success: function(result) {
console.log('Deleting Recipe...');
window.location.href = '/';
},
error:function(err){
console.log(err);
}
});
}
});
});


Here is the button
<button class="btn btn-danger delete-salary data-id="{employee_id}">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>

Ответить
@tyresew.4233
@tyresew.4233 - 03.09.2018 05:10

(TRAVERYSY STUDENTS I installed nodemon to help with the things. )

Ответить
@tanyaromero4517
@tanyaromero4517 - 18.09.2018 18:15

In the new version I have to replace the 2nd line to: $("button.btn.delete-recipe").click(function(){

Ответить
@putrastrikepro6371
@putrastrikepro6371 - 18.05.2022 06:01

Do you have tutorial how can I use turn ajax into fetch API with postgresql

Ответить