e.preventDefault ();不使用https



我使用bluehost来托管一个通过node.js express提供服务的网页

var app = express();
app.listen(80);

您可以使用端口80 (HTTP)或端口443 (https)导航到页面。实际上,我只是在页面URL前手动输入HTTP或https来控制它。

我有一个表单在ejs页面与jquery等待表单提交,当它提交时,我使用e.p preventdefault()来阻止页面重新加载,然后使用ajax发送这个表单数据到节点服务器。当我希望节点服务器响应并运行成功函数时,ejs页面有一些看起来不错的CSS转换。这既适用于本地,也适用于使用HTTP托管的页面。如果我使用https连接,表单数据实际上不会传递到服务器(当提交表单时,它会在服务器端显示console.log的一些信息),页面只是刷新。是什么问题导致了这种不同的行为?

感谢您的帮助

编辑:

这是不允许页面刷新的表单的客户端代码,但是当通过https连接时将刷新而不发布。

<form id="sendmessageform" name="sendmessageform">
<input type="text" name="logcustomername" placeholder="Customer Name" id="logcustomername" autocomplete="off">
<input type="tel" name="logcustomernumber"  placeholder="Customer Phone Number" id="logcustomernumber" autocomplete="off">
<input type="text" name="logstorename"  placeholder="Store Name" id="logstorename" autocomplete="off">
<input type="submit" value="Submit"/>
</form>
<script>
$('#sendmessageform').submit(function(e){
e.preventDefault();
$.ajax({
url: '/submit',
type: 'post',
data:$('#sendmessageform').serialize(),
success:function(data){
console.log(data)
}
});
});
</script>

此路由的服务器端

app.post('/submit',
function(req, res){
console.log(req.body)
var temp = new Object();
temp["statustype"] = "pass";
temp["content"] = "message contents.";

// return a temporary json object to the client
res.send(temp);
});

Edit2:

我试过改变e.p stopimmediatepropagation()的e.p preventdefault(),当提交按钮被点击时,页面不再刷新,即使在https上。我现在唯一的问题是,提交表单和服务器控制台。当我连接到HTTP时记录表单数据,但当我连接到https时什么也没发生。就好像ajax根本没有尝试发送表单一样。

看起来像是一个简单的错误。我尝试在jquery函数的顶部添加一个警告("Test")框,当单击按钮时没有弹出,这告诉我这不是表单本身的问题,而是jquery本身没有试图运行。看看我的头,我使用HTTP而不是https引用jquery源,所以当我用https连接时,我的浏览器给出了一个错误,这是不允许的。将源URL更改为https://完全解决了这个问题。

相关内容