',{'class':'img_div'});
var zImg=$('',{'src':valu['small'],'rel':valu['big']});
//--------------------------------
zDiv.append(zImg);
$('#allpics').find('#zclose').before(zDiv);
});
//----------------------------------------------------------------------------------------------
$.ajax ( {
type: 'POST',
url: '=$_SERVER['PHP_SELF']?>',
data: {step:'', favpic:inpic}
}).done(
function(html) {
//alert(html);
});
//----------------------------------------------------------------------------------------------
$.ajax({
url: "test.html",
context: document.body
}).done(function() {
$(this).addClass("done");
});
//--------------------------------------------
$.ajax({
statusCode: {
404: function() {
alert("page not found");
}
}
});
//--------------------------------------------
$.ajax({
url: a_cross_domain_url,
xhrFields: {
withCredentials: true
}
});
//--------------------------------------------
$.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));
}
});
//--------------------------------------------
var jqxhr = $.ajax( "example.php" )
.done(function() { alert("success"); })
.fail(function() { alert("error"); })
.always(function() { alert("complete"); });
// perform other work here ...
// Set another completion function for the request above
jqxhr.always(function() { alert("second complete"); });
//--------------------------------------------
$.ajax({
url: 'ajax/test.html',
success: function(data) {
$('.result').html(data);
alert('Load was performed.');
}
});
//--------------------------------------------
var _super = jQuery.ajaxSettings.xhr;
jQuery.ajaxSettings.xhr = function () {
var xhr = _super(),
getAllResponseHeaders = xhr.getAllResponseHeaders;
xhr.getAllResponseHeaders = function () {
if ( getAllResponseHeaders() ) {
return getAllResponseHeaders();
}
var allHeaders = "";
$( ["Cache-Control", "Content-Language", "Content-Type",
"Expires", "Last-Modified", "Pragma"] ).each(function (i, header_name) {
if ( xhr.getResponseHeader( header_name ) ) {
allHeaders += header_name + ": " + xhr.getResponseHeader( header_name ) + "\n";
}
return allHeaders;
});
};
return xhr;
};
//--------------------------------------------
$.ajax({
type: "POST",
url: "some.php",
data: { name: "John", location: "Boston" }
}).done(function( msg ) {
alert( "Data Saved: " + msg );
});
//--------------------------------------------
$.ajax({
url: "test.html",
cache: false
}).done(function( html ) {
$("#results").append(html);
});
//--------------------------------------------
var xmlDocument = [create xml document];
var xmlRequest = $.ajax({
url: "page.php",
processData: false,
data: xmlDocument
});
xmlRequest.done(handleResponse);
//--------------------------------------------
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({
type: "GET",
url: "test.js",
dataType: "script"
});
//--------------------------------------------
$.ajaxSetup({
url: 'ping.php'
});
$.ajax({
// url not set here; uses ping.php
data: {'name': 'Dan'}
});
//--------------------------------------------
$.ajaxSetup({
url: "/xmlhttp/",
global: false,
type: "POST"
});
$.ajax({ data: myData });
//--------------------------------------------
$.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");
})
.success(function() { alert("second success"); })
.error(function() { alert("error"); })
.complete(function() { alert("complete"); });
// perform other work here ...
// Set another completion function for the request above
jqxhr.complete(function(){ alert("second complete"); });
//--------------------------------------------
$.post("test.php");
$.post("test.php", { name: "John", time: "2pm" } );
$.post("test.php", { 'choices[]': ["Jon", "Susan"] });
$.post("test.php", $("#testform").serialize());
$.post("test.php", function(data) {
alert("Data Loaded: " + data);
});
$.post("test.php", { name: "John", time: "2pm" },
function(data) {
alert("Data Loaded: " + data);
});
$.post("test.php", { name: "John", time: "2pm" },
function(data) {
process(data);
},
"xml"
);
$.post("test.php", { "func": "getNameAndTime" },
function(data){
console.log(data.name); // John
console.log(data.time); // 2pm
}, "json");
//--------------------------------------------
//--------------------------------------------
$.ajax({
url: url,
data: data,
success: success,
dataType: dataType
});
//--------------------------------------------
$.get('ajax/test.html', function(data) {
$('.result').html(data);
alert('Load was performed.');
});
//--------------------------------------------
// Assign handlers immediately after making the request,
// and remember the jqxhr object for this request
var jqxhr = $.get("example.php", function() {
alert("success");
})
.success(function() { alert("second success"); })
.error(function() { alert("error"); })
.complete(function() { alert("complete"); });
// perform other work here ...
// Set another completion function for the request above
jqxhr.complete(function(){ alert("second complete"); });
//--------------------------------------------
$.get("test.php");
$.get("test.php", { name: "John", time: "2pm" } );
$.get("test.php", { 'choices[]': ["Jon", "Susan"]} );
$.get("test.php", function(data){
alert("Data Loaded: " + data);
});
$.get("test.cgi", { name: "John", time: "2pm" },
function(data){
alert("Data Loaded: " + data);
});
$.get("test.php",
function(data){
$('body').append( "Name: " + data.name ) // John
.append( "Time: " + data.time ); // 2pm
}, "json");
//--------------------------------------------
$('#result').load('ajax/test.html');
$('#result').load('ajax/test.html', function() {
alert('Load was performed.');
});
$('#result').load('ajax/test.html #container');
$('#a').load('article.html');
$('#b').load('article.html #target');
//--------------------------------------------
Footer navigation:
//--------------------------------------------
Successful Response (should be blank):Error Response:
//--------------------------------------------
$("#feeds").load("feeds.html");
$("#objectID").load("test.php", { 'choices[]': ["Jon", "Susan"] } );
$("#feeds").load("feeds.php", {limit: 25}, function(){
alert("The last 25 entries in the feed have been loaded");
});
//--------------------------------------------
$.ajax({
url: url,
dataType: 'json',
data: data,
success: callback
});
//--------------------------------------------
$.getJSON('ajax/test.json', function(data) {
var items = [];
$.each(data, function(key, val) {
items.push('
' + val + '
');
});
$('
', {
'class': 'my-new-list',
html: items.join('')
}).appendTo('body');
});
//--------------------------------------------
// Assign handlers immediately after making the request,
// and remember the jqxhr object for this request
var jqxhr = $.getJSON("example.json", function() {
alert("success");
})
.success(function() { alert("second success"); })
.error(function() { alert("error"); })
.complete(function() { alert("complete"); });
// perform other work here ...
// Set another completion function for the request above
jqxhr.complete(function(){ alert("second complete"); });
//--------------------------------------------
//--------------------------------------------
$.getJSON("test.js", function(json) {
alert("JSON Data: " + json.users[3].name);
});
//--------------------------------------------
$.getJSON("test.js", { name: "John", time: "2pm" }, function(json) {
alert("JSON Data: " + json.users[3].name);
});
//--------------------------------------------
$.ajax({
url: url,
dataType: "script",
success: success
});
//--------------------------------------------
$.getScript("ajax/test.js", function(data, textStatus, jqxhr) {
console.log(data); //data returned
console.log(textStatus); //success
console.log(jqxhr.status); //200
console.log('Load was performed.');
});
//--------------------------------------------
$.getScript("ajax/test.js")
.done(function(script, textStatus) {
console.log( textStatus );
})
.fail(function(jqxhr, settings, exception) {
$( "div.log" ).text( "Triggered ajaxError handler." );
});
//--------------------------------------------
$( "div.log" ).ajaxError(function(e, jqxhr, settings, exception) {
if (settings.dataType=='script') {
$(this).text( "Triggered ajaxError handler." );
}
});
//--------------------------------------------
$.ajaxSetup({
cache: true
});
//--------------------------------------------
jQuery.cachedScript = function(url, options) {
// allow user to set any option except for dataType, cache, and url
options = $.extend(options || {}, {
dataType: "script",
cache: true,
url: url
});
// Use $.ajax() since it is more flexible than $.getScript
// Return the jqXHR object so we can chain callbacks
return jQuery.ajax(options);
};
// Usage
$.cachedScript("ajax/test.js").done(function(script, textStatus) {
console.log( textStatus );
});
//--------------------------------------------
//--------------------------------------------
$('.log').ajaxComplete(function() {
$(this).text('Triggered ajaxComplete handler.');
});
$('.trigger').click(function() {
$('.result').load('ajax/test.html');
});
//--------------------------------------------
$('.log').ajaxComplete(function(e, xhr, settings) {
if (settings.url == 'ajax/test.html') {
$(this).text('Triggered ajaxComplete handler. The result is ' +
xhr.responseHTML);
}
});
//--------------------------------------------
$("div.log").ajaxError(function() {
$(this).text( "Triggered ajaxError handler." );
});
$("button.trigger").click(function() {
$("div.result").load( "ajax/missing.html" );
});
//--------------------------------------------
$( "div.log" ).ajaxError(function(e, jqxhr, settings, exception) {
if ( settings.url == "ajax/missing.html" ) {
$(this).text( "Triggered ajaxError handler." );
}
});
//--------------------------------------------
$("#msg").ajaxError(function(event, request, settings){
$(this).append("