티스토리 뷰

정보 보관 ver1.0

jQuery.ajax()

James Wetzel 2012. 9. 19. 17:18

Example: Send an id as data to the server, save some data to the server, and notify the user once it's complete. If the request fails, alert the user.

var menuId = $("ul.nav").first().attr("id");
var request = $.ajax({
  url
: "script.php",
  type
: "POST",
  data
: {id : menuId},
  dataType
: "html"
});

request
.done(function(msg) {
  $
("#log").html( msg );
});

request
.fail(function(jqXHR, textStatus) {
  alert
( "Request failed: " + textStatus );
});

$.ajax({
  url: "http://fiddle.jshell.net/favicon.png",
  beforeSend: function ( xhr ) {
    xhr.overrideMimeType("text/plain; charset=x-user-defined");
  }
}).done(function ( data ) {
  if( console && console.log ) {
    console.log("Sample of data:", data.slice(0, 100));
  }
});


상세 내용: http://api.jquery.com/jQuery.ajax/


728x90
반응형