带有基本 href 的 jQuery POST 问题
我必须在我的网站上使用
因为我使用的是 apache mod_rewrite,如果我不这样做,就会出现问题放置基本 href 标签。
但问题现在出在这个 jQuery 函数上:
$(document).ready(function(){
$("#submit_newsletter").click(function(){
var hasError = false;
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
var nameVal = $("#name").val();
if(nameVal == '') {
$("#name").addClass("highlightError").delay(4000).queue(function(){
$(this).removeClass("highlightError");
$(this).dequeue();
});
hasError = true;
}
var subnameVal = $("#subname").val();
if(subnameVal == '') {
$("#subname").addClass("highlightError").delay(4000).queue(function(){
$(this).removeClass("highlightError");
$(this).dequeue();
});
hasError = true;
}
var emailVal = $("#email").val();
if(emailVal == '') {
$("#email").addClass("highlightError").delay(4000).queue(function(){
$(this).removeClass("highlightError");
$(this).dequeue();
});
hasError = true;
} else if(!emailReg.test(emailVal)) {
$("#email").addClass("highlightError").delay(4000).queue(function(){
$(this).removeClass("highlightError");
$(this).dequeue();
});
hasError = true;
}
var messageVal = $("#message").val();
if(messageVal == '') {
$("#message").addClass("highlightError").delay(4000).queue(function(){
$(this).removeClass("highlightError");
$(this).dequeue();
});
hasError = true;
}
if(hasError == false) {
$.post("mail.php",
{ name: nameVal, subname: subnameVal, email: emailVal, message: messageVal },
function(data){
$("#results").text("Messaggio Inviato.").delay(4000).queue(function(){
$("#results").text("")
$(this).dequeue();
});
$('#newsletter')[0].reset();
}
);
}
return false;
});
});
当我删除基本 href 标签时,它工作得很好,当我使用它时(我重复一遍,我必须使用它),上面的 jQuery 函数停止工作。 它不会给出任何错误,只是不会将任何值传递给 mail.php 文件,并且不会返回任何结果。
如何使用基本 href 标签解决此 jQuery 问题?
谢谢。
I have to use <base href="http://www.mysite.com/it/"/>
on my site because I am using apache mod_rewrite, that causes issues if I do not put the base href tag.
But the problem is now coming with this jQuery function:
$(document).ready(function(){
$("#submit_newsletter").click(function(){
var hasError = false;
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
var nameVal = $("#name").val();
if(nameVal == '') {
$("#name").addClass("highlightError").delay(4000).queue(function(){
$(this).removeClass("highlightError");
$(this).dequeue();
});
hasError = true;
}
var subnameVal = $("#subname").val();
if(subnameVal == '') {
$("#subname").addClass("highlightError").delay(4000).queue(function(){
$(this).removeClass("highlightError");
$(this).dequeue();
});
hasError = true;
}
var emailVal = $("#email").val();
if(emailVal == '') {
$("#email").addClass("highlightError").delay(4000).queue(function(){
$(this).removeClass("highlightError");
$(this).dequeue();
});
hasError = true;
} else if(!emailReg.test(emailVal)) {
$("#email").addClass("highlightError").delay(4000).queue(function(){
$(this).removeClass("highlightError");
$(this).dequeue();
});
hasError = true;
}
var messageVal = $("#message").val();
if(messageVal == '') {
$("#message").addClass("highlightError").delay(4000).queue(function(){
$(this).removeClass("highlightError");
$(this).dequeue();
});
hasError = true;
}
if(hasError == false) {
$.post("mail.php",
{ name: nameVal, subname: subnameVal, email: emailVal, message: messageVal },
function(data){
$("#results").text("Messaggio Inviato.").delay(4000).queue(function(){
$("#results").text("")
$(this).dequeue();
});
$('#newsletter')[0].reset();
}
);
}
return false;
});
});
When I remove the base href tag it works just fine, when I use it ( and I repeat, I must use it ) the above jQuery function stops to work.
It does not give any error, simply it does not pass any value to the mail.php file, and does not return any result.
How can I fix this jQuery issue with the base href tag?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您没有在重写中重写您的查询字符串。 url 现在将是这样的,因为 jQuery $.post 默认类型是 GET 方法:
您可以在 jQuery 中使用 type : "post" 来不使用查询字符串。
如果你想保留 GET 方法,RewriteRule 应该是这样的:
I think you are not rewriting your querystring in the rewrite. The url will be something like this now, since jQuery $.post default type is the GET method:
You can use the type : "post" in jQuery to not use the querystring.
The RewriteRule if you want to keep your GET method should be something like this: