jquery 常用的后台交互脚本集合

jquery 常用的后台交互脚本集合

get

$.get( "ajax/test.html", function( data ) {
  $( ".result" ).html( data );
  alert( "Load was performed." );
});

$.get( "test.php", { name: "John", time: "2pm" } );

$.get( "test.php", { "choices[]": ["Jon", "Susan"] } );

$.get( "test.cgi", { name: "John", time: "2pm" } )
  .done(function( data ) {
    alert( "Data Loaded: " + data );
  });

post

$.ajax({
  type: "POST",
  url: url,
  data: data,
  success: success,
  dataType: dataType
});

$.post( "ajax/test.html", function( data ) {
  $( ".result" ).html( data );
});

// Assign handlers immediately after making the request,
// and remember the jqxhr object for this request
var jqxhr = $.post( "example.php", function() {
  alert( "success" );
})
  .done(function() {
    alert( "second success" );
  })
  .fail(function() {
    alert( "error" );
  })
  .always(function() {
    alert( "finished" );
  });

// Perform other work here ...

// Set another completion function for the request above
jqxhr.always(function() {
  alert( "second finished" );
});

猜你喜欢

转载自blog.csdn.net/rodneyzhaonet/article/details/80359132
今日推荐