javascript - AJAX DELETE Method Redirect Not Working -


i trying fix jquery ajax command there click on <a href="#"> triggers delete request specific url have route setup , redirect new page. delete portion of ajax working correctly, reason, success portion interpreting redirect /app delete request. doesn't seem recognize get have set before url , defaulting delete. can me determine part of method incorrect?

link:

<a href="javascript:void(0);" id="card-delete-link"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span>delete</a> 

jquery:

<script type="text/javascript">         $(document).ready(function() {             $('#card-delete-link').click(function(){                 $.ajax({                     method: 'delete',                     url: '/app/edit/{{card.cardid}}',                     success: function(){                         console.log('annotation id: ' + '{{card.cardid}}' + ' deleted');                         $.ajax({                             method: 'get',                             url:'/app'                         });                     }                 });             }); </script> 

browser console:

jquery.js:8630 delete http://localhost:3000/app 404 (not found) 

route:

approutes.route('/edit/:cardid')     .delete(function(req, res){         models.card.destroy({             where: {                 userid: req.user.userid,                 cardid: req.params.cardid                        }         }).then(function(){             res.redirect('/app');         });     }); 

in node.js using .delete verb, means ignore requests except delete method stipulated in headers. why request not handled. thereby, redirect on success window.location.replace() without making second request server. on other hand, if making second request critical, create new route

example:

app.get('/', function (req, res) {   res.send('get request homepage'); }); 

also, should rethink code, because won't able redirect ajax request.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -