我正在嘗試構建自己的WordPress主題,它似乎可行,但我遇到了電子郵件表單的問題。當我在適應WordPress之前使用它的代碼工作,但現在沒有。未找到Ajax調用php,404錯誤
$(function() {
$("#contactForm input,#contactForm textarea").jqBootstrapValidation({
preventSubmit: true,
submitError: function($form, event, errors) {
// additional error messages or events
},
submitSuccess: function($form, event) {
// Prevent spam click and default submit behaviour
$("#btnSubmit").attr("disabled", true);
event.preventDefault();
console.log ('1');
// get values from FORM
var name = $("input#name").val();
var email = $("input#email").val();
var phone = $("input#phone").val();
var message = $("textarea#message").val();
var firstName = name; // For Success/Failure Message
// Check for white space in name for Success/Fail message
if (firstName.indexOf(' ') >= 0) {
firstName = name.split(' ').slice(0, -1).join(' ');
console.log ('2');
}
$.ajax({
url: "./mail/contact_me.php",
type: "POST",
data: {
name: name,
phone: phone,
email: email,
message: message
},
cache: false,
success: function() {
// Enable button & show success message
console.log ('3');
$("#btnSubmit").attr("disabled", false);
$('#success').html("<div class='alert alert-success'>");
$('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
.append("</button>");
$('#success > .alert-success')
.append("<strong>Your message has been sent. </strong>");
$('#success > .alert-success')
.append('</div>');
JavaScript文件是在這條航線:domain/wp-content/themes/federo/js/contact_me.js
而且PHP文件是在這裏:domain/wp-content/themes/federo/mail/contact_me.php
它只是沒有找到頁面。你應該試試這個:'../ mail/contact_me.php' – Jai
我想錯了。我的意思是:如果您將URL替換爲:'「/wp-content/themes/federo/mail/contact_me.php」' –
非常感謝!!!它的工作,我覺得像一個愚蠢的,但你的幫助已經很大 – Federo