如果您添加到您的主頁的docReady,應該照顧一切:
$('form').live('submit', function(e){
var successHref = this.action,
errorHref = "formError.php";
e.preventDefault();
$('#cboxLoadingGraphic').fadeIn();
$.ajax({
type: "POST",
url: "processForm.php",
data: {someData: $("#someData").val()},
success: function(response) {
if(response=="ok") {
console.log("response: "+response);
$.colorbox({
open:true,
href: successHref
});
} else {
$.colorbox({
open:true,
href: errorHref
});
}
},
dataType: "html"
});
return false;
});
這段代碼的幾個假設,雖然。其中之一是,這將數據發送到「processForm.php」(正如你所看到的),並期望當一切正常時,回答「ok」(純文本,無json)。如果您不關心響應或處理錯誤,那麼您可以刪除if-else
塊,並打開您在action
中設置的頁面的彩色框。 Anway,你可能想要調整這個,但它讓你知道如何完成。
如果它解決了你的問題(這聽起來像是這樣),不要忘記在下面標記答案。 –