2011-09-09 11 views
0

ajaxを使用してページにロードされるフォームがあります。フォームは、malsup jqueryフォームプラグインを使用して送信されます。JQueryのajaxフォームの送信は、デバッグ時には動作しません。

奇妙なことに、このメソッドにFirebugブレークポイント行または警告を追加するとフォームが機能しますが、警告またはデバッグを削除すると、送信コードは決して実行されません。

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を使って試してみましたが、違いはありません。

アイデア?

+0

を試してみてください。 – Matt

答えて

0

はあなたが完了し、ロードした後、あなたの関数の後の部分を呼び出す必要があるかもしれませ、あなたは答えとしてあなたのソリューションを追加し、それを自分で受け入れる、という質問には、それを追加するよりもする必要があり、この

$(document).ready(function(){ 

     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); 

      } 
        Dowork();//function call after load complete 
     }); 
    } 


    function Dowork(){ 
      var prefix = typeSplit[0]; 
     var type = typeSplit[1]; 
     //this alert will cause the submit form to 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; 
     }); 
    } 
    }); 
+0

それはそれだった...ありがとう – Lee

関連する問題