Jquery 为什么我的请求没有到达服务器?-在本地工作,但不在服务器上工作
我有一个带有JQuery的基本HTML网站,它向节点服务器提交Ajax POST请求一切正常在我的机器Windows上本地运行,我可以在浏览器中提交表单,在服务器上获取请求并发送适当的响应,但是在我的VPS droplet上,没有任何内容到达POST路由。。不过,我的GET“/”运行良好 这是我的app.js 这是我对客户的要求Jquery 为什么我的请求没有到达服务器?-在本地工作,但不在服务器上工作,jquery,node.js,ajax,express,nginx,Jquery,Node.js,Ajax,Express,Nginx,我有一个带有JQuery的基本HTML网站,它向节点服务器提交Ajax POST请求一切正常在我的机器Windows上本地运行,我可以在浏览器中提交表单,在服务器上获取请求并发送适当的响应,但是在我的VPS droplet上,没有任何内容到达POST路由。。不过,我的GET“/”运行良好 这是我的app.js 这是我对客户的要求 frm.submit(function (e) { e.preventDefault(); $.ajax({
frm.submit(function (e) {
e.preventDefault();
$.ajax({
type: "POST",
url: "https://www.localhost.ca:8080/contact",
data: frm.serialize(),
success: function (data) {
if (data.err && data.user_generated) {
$('.output-message').text("Message not sent: " + data.error_contents);
$('.output-message').css("color", "red");
} else if (data.err) {
$('.output-message').text("Internal Server Error - Please try again in a couple of moments");
$('.output-message').css("color", "red");
} else {
$('.output-message').text("Message sent succesfully!");
$('.output-message').css("color", "green");
document.getElementById('contact-form').reset();
}
},
error: function (data) {
if (data.err && data.user_generated) {
$('.output-message').text("Message not sent: " + data.error_contents);
$('.output-message').css("color", "red");
} else if (data.err) {
$('.output-message').text("Internal Server Error - Please try again in a couple of moments");
$('.output-message').css("color", "red");
}
}
});
});
假设是服务器设置导致了这个问题,我设置了一个新的Ubuntu Droplet并安装了节点,我还[使用此方法][1]设置了一个SSL证书。如果有帮助的话,我可以发布我的Nginx配置。。除此之外,我真的被难住了。我现在已经设置了两个水滴,两个水滴都找不到帖子。。显然使用了同样的错误策略
奇怪的是,它在本地运行得非常完美,所以我认为它很好,任何问题或建议都将不胜感激
编辑:
这是我的NGINX配置文件
server {
listen 80 default_server;
listen [::]:80 default_server;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/tycoonmedia/src;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name tycoonmedia.ca www.tycoonmedia.ca;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
try_files $uri $uri/ =404;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php7.0-fpm:
# fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/tycoonmedia.ca/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/tycoonmedia.ca/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
if ($scheme != "https") {
return 301 https://$host$request_uri;
} # managed by Certbot
# Redirect non-https traffic to https
# if ($scheme != "https") {
# return 301 https://$host$request_uri;
# } # managed by Certbot
}
# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
server {
# listen 80;
# listen [::]:80;
#
# server_name tycoonmedia.ca www.tycoonmedia.ca;
#
# root /var/www/tycoonmedia/src;
# index index.html;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}
[1]: https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let
-s-encrypt-on-ubuntu-16-04我认为,nginx配置中代理设置中的这一行导致了这个问题:
try_files $uri $uri/ =404;
卸下它并重新加载nginx,您应该没事了 这将更容易用AJAX错误响应进行诊断。@Chase抱歉,我应该注意到响应非常慢,并且我得到了一个net::ERR\u CONNECTION\u TIMED\u OUT错误。我已经尝试过使用Postman的各种请求配置,我得到的最好结果是超时。你的帖子正常吗?curl-v-X POST-d'somedata'http://yourserver/your/post/path 结果是?@I.R.R.我得到了一个永久移动的Nginx页面..那就把它缩小到Nginx配置了。发布您的Web服务器配置,nginx的优秀人员可能会注意到发生了什么。
try_files $uri $uri/ =404;