在jQuery中,可以使用以下幾種方式實(shí)現(xiàn)Ajax請(qǐng)求:
$.ajax({
type: "POST",
url: "example.php",
data: { name: "John", age: 30 },
success: function(response){
console.log(response);
}
});
$.get("example.php", function(response) {
console.log(response);
});
$.post("example.php", { name: "John", age: 30 }, function(response) {
console.log(response);
});
$.getJSON("example.php", function(response) {
console.log(response);
});
$.ajaxSetup({
url: "example.php",
type: "POST"
});
$.ajax({ data: { name: "John", age: 30 } });
$.ajax({ data: { name: "Jane", age: 25 } });
這些是jQuery中常見的幾種方式,根據(jù)具體的需求和場(chǎng)景選擇合適的方式來發(fā)送Ajax請(qǐng)求。