0
我有一個使用ajax加載到頁面的表單。然後使用malsup jquery表單插件提交表單。JQuery ajax表單在調試時提交,但不是沒有
奇怪的是,當我在此方法中添加一個螢火蟲斷點行或警報時,表單很有效,但是當我刪除警報或調試時,提交代碼從不運行。
function addAttachment(attachmentType, path){
var typeSplit = attachmentType.split(":");
if(path == null){
path = "";
}
var url = "/add/" + typeSplit[0] + "/" + typeSplit[1];
addOverlayDivs(); //adds div to load the form into
// load the form
var snippet = $('#overlay').load(url, function(response, status, xhr) {
if (status == "error") {
var msg = "Sorry but there was an error: ";
$("#overlay").html(msg + xhr.status + " " + xhr.statusText);
}
});
var prefix = typeSplit[0];
var type = typeSplit[1];
//this alert will cause the submit form to work
alert("bind overlay called");//if I comment this out the formsubmit doesn't work
var options = {
target: null, // target element(s) to be updated with server response
beforeSubmit: showRequest,
success: showResponse,
url: "/add/" + prefix + "/" + type,
type: "POST",
dataType: "json"
};
$('#overlayForm').submit(function() {
$(this).ajaxSubmit(options);
// always return false to prevent standard browser submit and page navigation
return false;
});}
我試過了,沒有使用$(document).ready,並沒有什麼區別。
任何想法?
您應該添加您的解決方案作爲一個答案,自己接受它,而不是將它添加到的問題。 – Matt