2014-03-31 71 views
1

我有一個名爲#pageToLoad的div。頁面formPage.php在該div中加載一個表單。我需要知道該頁面是否完全加載到div中。因此,如果出現任何錯誤,我可以使用重置表單;檢查div是否已完全加載ajax

$("#form").reset(); 

我該如何創建一個事件?

$("#pageToLoad").load("formPage.php"); 

回答

0

您需要$.ajax(complete:function(responseText, textStatus, XMLHttpRequest)){});登記和檢查textStatus值。如果確定,然後將數據加載到目標$('selector')自己

$.get("formPage.php").success(
    function(response, status, jqXhr){ 
     alert("Success!"); 
    }).error(function (response, status, jqXhr){ 
     alert("These is error."); 
    }).complete(function (response, status, jqXhr){ 
     alert("Complete!"); 
    }); 

OR

$("#pageToLoad").load("formPage.php", function(response, status, xhr) { 
if (status == "error") { 
var msg = "Sorry but there was an error: "; 
$("#error").html(msg + xhr.status + " " + xhr.statusText); 
} 
}); 
0
$("#pageToLoad").load("formPage.php", function(response, status, xhr) { 

if (status == "error") { 
    // "Sorry but there was an error: "; 

} 
else{ 
     $("#form").reset(); 
} 
}); 
相關問題