For example purpose any example load the ajax result in a different div adjusting the target plugin option. Btw the target div is clean up before any code injection so that all the examples could have been pointed to the same target
Basic usage
Note the first link ( image 1 ) is intentionally broken to test the error response. Server response is delayed of 2 sec to see the loading message.
$('.ajax').ajaxContent();
HTML
<a class="ajax" href="examples/ajaxcontent/gallery.cfm?pi=image1">Image 1</a>
<a class="ajax" href="examples/ajaxcontent/gallery.cfm?pic=image2">Image 2</a>
<a class="ajax" href="examples/ajaxcontent/gallery.cfm?pic=image3">Image 3</a>
Event is triggered on mouseover and load content from html files instead that from a dynamic template.
$('.ajax2').ajaxContent({
event:'mouseover',
target:'#ajaxContent2'
});
<a class="ajax2" href="examples/ajaxcontent/htmla.htm">Text 1</a>
<a class="ajax2" href="examples/ajaxcontent/htmlb.htm">Text 2</a>
<a class="ajax2" href="examples/ajaxcontent/htmlc.htm">Text 3</a>
Change default loading message
loaderType is now IMG and loadingMsg supply the relative path to the img to display during the loading process.
$('.ajax3').ajaxContent({
loaderType:'img',
loadingMsg:'loading.gif',
target:'#ajaxContent3'
});
HTML AS first example
Highlight selected item.
By default the item that trigger the event receive the class "selected". The class can be changed and will affect only the set of items to which is referred. We use here a callback to demostrate that this set of items receive the customized class"current".
$('.ajax4').ajaxContent({
target:'#ajaxContent4',
currentClass:"current",
success: function(obj,target,msg){
alert($(obj).attr('class'));
}
});
HTML AS first example
Callbacks and Error Message
The Error Message used by the plugIn can be personalized as follow.
The plugin provide 3 different callabcks that can be called from the options line.
"beforeSend" run before the ajax call starts and take 2 arguments
- obj : is the jQuery object that represet the item on which the event is triggered
- target : is the element to be filled by the ajax call
"success" run if the ajax call is completed and take 3 arguments
- obj : is the jQuery object that represet the item on which the event is triggered
- target : is the element to be filled by the ajax call
- msg : is the message received as response by the server
"error" run if the ajax call is broken and take un argument
- target : is the element to be filled by the ajax call
$('.ajax5').ajaxContent({
target:'#ajaxContent5',
beforeSend:function(obj,target){
alert('I am an ajaxContent link with classes:' + $(obj).attr('class') + "\n" + 'and my target has id:' + $(target).attr('id'));
},
success: function(obj,target,msg){
$(obj).css({color: 'blue'});
$(target).css({border:'7px solid blue'});
},
error: function(target){
$(target).css({color: 'red',fontSize:'24px',border:'3px dotted ##FF0000'});
},
errorMsg:'Something went wrong'
});
HTML AS first example
Extend to injected code
From version 2.1 the plugin offer a set of EXTEND options to attach a new 100% customizabile ajax event to the code injected from the fisrt call. For running the new event you must set the "extend" options to "true" and supply the plugin the "filter" attribute that represent the element injected from the first call that will receive the instructions to perfom the new ajax event. Basically the behaviour was possible using the liveQuery plugin with a bit of overhead respect to the embedded ajaxContent functionality.
All the settings that are normally used to personalize ajaxContent are provided with "ex_" prefix to customize the second event
By default the second event looks as en element with id "ajaxExtend" as target element
Basic Extend Example
$('.ajax8').ajaxContent({
target:'#ajaxContent8',
extend:'true',
filter:'.ajaxLoad',
ex_target:'#ajaxContent9'
});
<a class="ajax8" href="examples/ajaxcontent/extend.cfm">Click to load the perform the first call</a>
HTML INJECTED FROM THE FIRST CALL
<a class="ajaxLoad" href="gallery.cfm?pic=image1">Load Image 1 in the new specified target</a>
Click to load the perform the first call
Personalize the extended event
the extended event is fully personalizable using the same options avalable for the normal behaviour with the ex_prefix.
$('.ajax9').ajaxContent({
target:'#ajaxContent10',
extend:'true',
filter:'.ajaxLoad',
ex_target:'#ajaxContent11',
ex_loadingMsg:'This is a personalized loading message set by ex_loadingMsg option',
ex_beforeSend:function(obj,target){
alert('ex_beforeSend option callback');
},
ex_success:function(obj,target,msg){
alert('ex_success option callback. The target background will now become red');
$(target).css({backgroundColor:'red'});
}
});
<a class="ajax8" href="examples/ajaxcontent/extend.cfm">Click to load the perform the first call</a>
HTML INJECTED FROM THE FIRST CALL
<a class="ajaxLoad" href="gallery.cfm?pic=image1">Load Image 1 in the new specified target</a>
Click to load the perform the first call
Form items Binding (depend on forms.js jquery plugin)
"Bind" attribute gives the ajaxContent link the ability to update the parameters in his own query string onchange of a binded form element. This gives the plugin a great flexibility and a lot of more power.
Some basic rules to follow especially for radio and checkbox are in the plugin API
$('.ajax10').ajaxContent({
target:'#ajaxContent12',
bind:'#name,#secondName,#dog,#cat,#sport'
});
<a clas="ajax10" href="examples/ajaxcontent/bindings.cfm">Click here!</a>
My Name is :
My Second Name is:
Do I have a dog?:
Do I have a cat?: YesNo
My preferred sports are : Soccer baseball basket
Bind the extend event
An ex_bind attribute is provided to bind also the extended event attached to an item called in the page by the previous ajax call
In the example perfom the first call and after use the select to decide with image to load in the next div
$('.ajax11').ajaxContent({
target:'#ajaxContent13',
extend:'true',
filter:'.ajaxLoad',
ex_target:'#ajaxContent14',
ex_loadingMsg:'Custom loading message for the extended div',
ex_bind: '#pic'
});
<a clas="ajax11" href="examples/ajaxcontent/extend2.cfm">Click here!</a>
HTML INJECTED FROM THE FIRST CALL
<a class="ajaxLoad" href="examples/ajaxcontent/gallery.cfm">Select a pic and then clik me.</a>
Select a pic to load:
Debug
If required and if Firebug is installed and running, the plugin show in the console the size and the class of the jQuery object involved
$('.ajax6').ajaxContent({
target:'#ajaxContent6',
debug: 'true'
}
});
Use the Metadata Plugin
If the metadata plugin is installed the options will be pulled from the element class attribute.
BTW the metadata plugin is not required for the plugin to work fine in the traditional way.
$('.ajax7').ajaxContent();
HTML
<a class="ajax7 {target:'#ajaxContent7',loaderType:'img',loadingMsg:'loading.gif'}" href="examples/ajaxcontent/gallery.cfm?pic=image1">Image 1</a>
Override Defaults
Any default value can be override setting the $.fn.ajaxContent.[option name] function. As you see in the code below this can be made also from outside a $(document).ready block.
THE FOLLOWING CODE CHANGE THE DEFAULT PLUGIN SETTING FOR ANY EVENT IN THE PAGE
(for obvious reason this code do not run on this examples presentation)
.......
$.fn.ajaxContent.defaults.errorMsg = 'This message override the defaults errro message';
$.fn.ajaxContent.defaults.event = 'focus';
$.fn.ajaxContent.defaults.debug = 'true';
$(document).ready(function(){
$('.ajax').ajaxContent();
});
9 Comments | RSS
1 Rick Faircloth December 10, 2008 09:03
Looks good, Andrea! I'm going to see what I can do with this on some new sites! Thanks,! Rick
Reply Andrea December 10, 2008 14:56
Thanks Rick, let me have your feedbacks.
2 fdfdfd December 17, 2008 20:49
ffffffdfdfdfddf
3 margo January 5, 2009 01:17
6iKsSK flHsdt83Nncfooi61t
4 Zwtgvxvn January 6, 2009 12:14
<a href=" http://www.scam.com/member.php?u=105118 ">mature pussy</a> %[[
5 Zcqqfdmc January 6, 2009 15:28
Good crew it's cool :) <a href=" http://www.scam.com/member.php?u=105120 ">anal sex</a> 787
6 Wsyktkmy January 6, 2009 17:06
Thanks funny site <a href=" http://forum.indya.com/member.php?u=136042 ">sextv1</a> 36026
7 Volhnuns January 6, 2009 20:18
very best job <a href=" http://forum.indya.com/member.php?u=136044 ">Pornography addiction</a> kner
8 Fepgiivw January 6, 2009 23:36
magic story very thanks <a href=" http://forum.indya.com/member.php?u=136045 ">Pornvue</a> 501
9 Xyojonyi January 7, 2009 02:49
Thanks funny site <a href=" http://forum.indya.com/member.php?u=136047 ">Vita tube videos</a> yjtsw