2014-02-28 95 views
-1

我有一個相當基本的註冊表單。我試圖顯示一條成功消息(頁面上,在彈出窗口中,在一個警報......我沒有偏好)VS.重定向到表單發佈到的頁面(這是當前正在發生的事情)。在表單提交而不是重定向時顯示消息

<form action="path/to/form/main/index.php" method="post"> 
<p> 
<input name="contact[first_name]" placeholder="Your First Name" type="text"> 
<input name="contact[email]" placeholder="[email protected]" type="text"> 
<input class="btn btn-success btn-large" value="Sign Me Up" type="submit"> 
</p> 
<input name="action" value="ext_addcontact" type="hidden"> 
<input name="selectedgroupname" value="Website Opt-Ins" type="hidden"> 
<input name="groupownerid" value="[p:pid]" type="hidden"> 
</form> 

[p:pid]是用於填充服務器端的系統的變量標籤。
例如:http://aia.dmplocal.com/sites/52/index.html
對不起,在這裏的任何白癡 - 我很新的JS/AJAX。謝謝

編輯:我無法控制表單發佈到的位置(index.php)。

+0

最簡單的方法是將重定向添加到您的PHP代碼。在保存表單數據(我假設發生在index.php)後,你可以添加一行:'header('Location:my_success_page.php');' –

+0

你好馬特 - 我很樂意,但我不'無權訪問編輯index.php。它幾乎需要一個解決方案,我可以在頁面內完成(我完全可以控制) – user3366357

+0

@MattBrowne仍然是一個重定向,這不是OP想要的。 – putvande

回答

0

Malsup的jQuery Form Plugin將是一個很好的開始。這是非常容易設置和使用。我已經使用過好幾次了。

這應該讓你開始:

$(function() { 
    $('form').ajaxForm({ 
     // Use this property to specify how your data will 
     // look when it's returned (i.e. JSON, XML, HTML, 
     // etc). If you aren't returning any data, you can 
     // omit this property. 
     dataType: ..., 
     success: function (res) { 
      // Do something in here on success. Depending on your 
      // requirements you may or may not have a result 
      // returned to you. 
     }, 
     error: function (res) { 
      // Do something in here on error. You should always 
      // have an error object passed to you that details 
      // the error and possibly any returned error text. 
     } 
    }); 
}); 

對於提供給你選項的完整列表,請參閱this API參考頁。

+0

我沒有時間在今天下午晚些時候執行此操作,但它看起來很傻(看過我的話),我發現沒有理由不能像所描述的那樣工作。感謝您幫助我將腳趾浸入新水域! – user3366357

相關問題