如何绑定和加载方法

How to tie bind and load methods?

本文关键字:加载 方法 绑定 何绑定      更新时间:2023-09-26

将页面上的内容加载到另一个页面。如果信息读取不正确,那么您应该使用bind()方法来显示有关该信息的消息。怎么做呢?

$("#result").load("university.html");

如果你只想知道请求是否成功,你可以使用回调函数。

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