我在最近转换为wordpress网站的网站上有ajax联系表单。联系表格工作正常,直到我将其转换为wp网站。现在只需将您输入到输入中的信息与其创建一个新页面即可。我知道它正在发生什么,不知道从哪里开始。联系表格带您到新页面
You can check the page out here
有这样的事情发生和/或任何解决方案的经验吗?
我在最近转换为wordpress网站的网站上有ajax联系表单。联系表格工作正常,直到我将其转换为wp网站。现在只需将您输入到输入中的信息与其创建一个新页面即可。我知道它正在发生什么,不知道从哪里开始。联系表格带您到新页面
You can check the page out here
有这样的事情发生和/或任何解决方案的经验吗?
我不知道怎么样事情是在Wordpress或jQuery中完成的,但是你的JavaScript函数需要稍微改变,我想和代码需要在<head></head>
部分理想。
jQuery(document).ready(function($) {
$("#ajax-contact-form").submit(function(event) {
/* Prevent the form actually submitting in standard manner */
event.preventDefault();
var str = $(this).serialize();
$.ajax({
type: "POST",
url: "/includes/contact-process.php",
data: str,
success: function(msg) {
// Message Sent? Show the 'Thank You' message and hide the form
if(msg == 'OK') {
result = '<div class="notification_ok">Your message has been sent. Thank you!</div>';
$("#fields").hide();
} else {
result = msg;
}
$('#note').html(result);
}
});
return false;
});
});
而且,您需要在您的ajax函数中使用的路径也需要更改 - 已在上面进行了编辑。 (刚刚尝试时我得到了404)
与Rasclatt的解决方案一样。新的页面加载问题已消失,但联系表单现在不做任何事情。 –
您是否在现场进行了更改,以便我们看到?我可以看到函数已经移动,但是你没有编辑路径,正如我提到的...它仍然返回404 ...它应该是'/ includes/contact-process.php' – RamRaider
是的它是最新的。 –
如果您在控制台看(查看源代码的网页),您的jQuery的形式Ajax是在就在你的页面的顶部,这样jQuery库来加载后声明该功能。
....etc...
<script type="text/javascript" src="http://www.spincycleprodcution.com/wp-content/themes/spincycle/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
// we will add our javascript code here
jQuery(document).ready(function($) {
$("#ajax-contact-form").submit(function() {
var str = $(this).serialize();
$.ajax({
type: "POST",
url: "includes/contact-process.php",
data: str,
success: function(msg) {
// Message Sent? Show the 'Thank You' message and hide the form
if(msg == 'OK') {
result = '<div class="notification_ok">Your message has been sent. Thank you!</div>';
$("#fields").hide();
} else {
result = msg;
}
$('#note').html(result);
}
});
return false;
});
});
</script>
</head>
您当前的控制台错误是:
ReferenceError: Can't find variable: jQuery (anonymous function)
因为你加载之前jQuery库,以便加载功能后jQuery库加载<head>
和年底前应登陆它无法找到jQuery。你甚至可以加载你的AJAX在页脚....或任何真正落后于jQuery库。
一旦你的AJAX的工作,你需要确保阿贾克斯可以找到参考页:
contact-process.php
,或者您收到此错误:
[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (contact-process.php, line 0)
在您的联系页面的'head'之外有代码。此外,联系表单javascript不会阻止发生默认操作。 – RamRaider
我需要添加什么来解决这个问题? –