08.jQuery - AJAX
jQuery - AJAX
The
jQuery load()
method is a simple, but powerful AJAX method.
The load()
method loads data
from a server and puts the returned data into the selected element.
$("button").click(function(){
$("#div1").load("demo_test.txt", function(responseTxt, statusTxt, xhr){
if(statusTxt == "success")
alert("External content loaded successfully!");
if(statusTxt == "error")
alert("Error: " + xhr.status + ": " + xhr.statusText);
});
});
HTTP Request: GET vs.
POST
Two
commonly used methods for a request-response between a client and server are:
GET and POST.
- GET -
Requests data from a specified resource
- POST -
Submits data to be processed to a specified resource
GET
$("button").click(function(){
$.get("demo_test.asp", function(data, status){
alert("Data: " + data + "\nStatus: " + status);
});
});
POST
$("button").click(function(){
$.post("demo_test_post.asp",
{
name: "Donald Duck",
city: "Duckburg"
},
function(data, status){
alert("Data: " + data + "\nStatus: " + status);
});
});
Comments
Post a Comment