Ajax post request doesn't work
Author: Zver64Created Nov 17, 2017Updated Oct 20, 2025
Issue details
Hi guys! I'm trying to get the .html file in my project folder and append it to another html page via ajax. But when i try to use jquery $.(post) method it says that the file is not found. But everything works great with the get method. So this code doesn't work:
$('[data-ajax1]').click(function (e) {
e.preventDefault();
$.post('ajax/popup-review.html', function (response) {
$('body').append(response);
});
});but this does:
$('[data-ajax1]').click(function (e) {
e.preventDefault();
$.get('ajax/popup-review.html', function (response) {
$('body').append(response);
});
});Here is the error i get: POST http://localhost:3000/ajax/popup-review.html 404 (Not Found)
Thank you for responding!
Please specify which version of Browsersync, node and npm you're running
- Browsersync [ 2.2.3 ]
- Node [ 6.11.5 ]
- Npm [ 5.5.1 ]
Affected platforms
- linux
- windows
- OS X
- freebsd
- solaris
- other (please specify which)
Browsersync use-case
- API
- Gulp
- Grunt
- CLI
If CLI, please paste the entire command below
{cli command here}
for all other use-cases, (gulp, grunt etc), please show us exactly how you're using Browsersync
var serve = {
server: {
baseDir: '.tmp',
routes: {
'/bower_components': 'bower_components'
}
},
host: 'localhost',
port: 3000,
open: false,
// tunnel: "geminis",
logPrefix: "Geminis"
};
gulp.task('default', ['light'], function() {
browserSync.init(serve);
gulp.watch(path.src.styles + '*.scss', ['styles']);
gulp.watch('src/ajax/*.html', ['ajax']);
gulp.watch(path.src.html + '**/*.html', ['njk-watch']);
gulp.watch(path.src.js + '*.js', ['scripts']);
gulp.watch(path.src.img + '**/*.*', ['image:copy']);
gulp.watch(path.src.img + 'icons/*.svg', ['svgsprites']);
});Source: BrowserSync/browser-sync