jQuery是否可以“替换” AJAX?

I'm a newbie, I worked with basic -AJAX techniques- like one year ago.

One month ago I realized jQuery exists and I'm using it in a basic way as well.

What I want to know is if jQuery can do things like AJAX does and/or "replace" it.

Example taken from w3schools: Can this be created with jQuery ?

function loadXMLDoc()
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
}

Yes. jQuery's ajax method is simply a wrapper. However, it takes care of browser-specific bugs and issues for you and provides a friendlier interface for configuring/executing requests.

If you're using jQuery, there is a built in .ajax() function that replaces ALL of that code. It also handle cross-browser issues. I recent re-write an entire website's worth of ajax code to look more like this.

Example:

$.ajax({
    url: 'fetchInfo.php',
    success: function(data) {
        $('.result').html(data);
        alert('Load was performed.');
    }
});

Definitely:

$.get('ajax_info.txt', function(data) {
 $('#myDiv').append(data);
});

No. AJAX is a design pattern used to introduce dynamic behavior or data to webpages, without resorting to the page reload.

jQuery is a Javascript framework. One of the things it can do is load data dynamically, in the AJAX pattern.

One does not replace the other.

you can do AJAX without jQuery and vice versa; or you can do them together.

Take a look at the jQuery API around the 4th link.

It should say jQuery.ajax()

jQuery is a framework for JavaScript, that makes JS code eaiser and cross-browser. The code you provided can be made in jQuery as follows:

$.get('ajax_info.txt', function(data){
  $('#myDiv').html(data);
});

Or even easier as:

$('#myDiv').load('ajax_info.txt');

jQuery API

yes, that is built into jquery. see http://api.jquery.com/category/ajax/

Yes, jQuery is powerful, even has function such as .ajaxPrefilter(), .ajaxStart(), .ajaxSend(), .ajaxError(), .ajaxStop(), ...

You can create above code with jQuery, just first you declare script for jQuery library such as:

<script type="text/javascript" src="jquery-address"></script>

Example:

$(document).ready(function(){
    $.ajax({
        url:"ajax_info.txt",
        type:"POST",
        data:"key1="+value1+"&key2="+value2,
        success:function(msg){$("#myDiv").text(msg);}  
    });  
});