I think this should do what you are trying to achieve:
var app = Davis(function () { this.get('/', function (req) { var xhr = $.ajax('/', { data: { id: req.params.id }, dataType: 'html' }) xhr.then(function (data) { var html = $(data) html.find('.close').on('click', function () { history.back() }) $('.a').before(html) }) }) })
The req
object that is passed to the route handler is not an ajax request, it is an object representing a "request" to the path, in this case /
, more of docs .
You need to do whatever work you want to do when the routeβs internal feedback is called on the link, in your case it looks like you want to make a request to a server that will respond to the cut html (I'm not a PHP developer, so this may be wrong). Then you want to add this html after the link in the current document.
Davis is not intended for routing based on query parameters, so you should not use them in the path definition, so I changed it to /
.
source share