2015-11-05 29 views
1

我在最近轉換爲wordpress網站的網站上有ajax聯繫表單。聯繫表格工作正常,直到我將其轉換爲wp網站。現在只需將您輸入到輸入中的信息與其創建一個新頁面即可。我知道它正在發生什麼,不知道從哪裏開始。聯繫表格帶您到新頁面

You can check the page out here

有這樣的事情發生和/或任何解決方案的經驗嗎?

+0

在您的聯繫頁面的'head'之外有代碼。此外,聯繫表單javascript不會阻止發生默認操作。 – RamRaider

+0

我需要添加什麼來解決這個問題? –

回答

1

我不知道怎麼樣事情是在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)

+0

與Rasclatt的解決方案一樣。新的頁面加載問題已消失,但聯繫表單現在不做任何事情。 –

+0

您是否在現場進行了更改,以便我們看到?我可以看到函數已經移動,但是你沒有編輯路徑,正如我提到的...它仍然返回404 ...它應該是'/ includes/contact-process.php' – RamRaider

+0

是的它是最新的。 –

0

如果您在控制檯(查看源代碼的網頁),您的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)

+0

這會停止新的頁面加載問題,但聯繫表單現在不執行任何操作。 –

+0

這是因爲它找不到你的'includes/contact-process.php'頁面 – Rasclatt

+0

錯誤:'無法加載資源:服務器響應狀態爲404(Not Found)(contact-process.php,line 0 )' – Rasclatt

相關問題