/*
Get and post methods that prevent repeated Ajax requests
*/
Jquery. Extend ({
Getx: Function (URL, Data, callback, Sender ){
VaR Params = {URL: URL, data: Null , Callback: Null , Sender: Null };
For ( VaR I = 1 ; I < Arguments. length; I ++ ){
If (Arguments [I] ! = Null ){
VaR Ptype = Typeof (Arguments [I]);
If (Ptype = " Function " ){
Params. Callback = Arguments [I];
}
Else If (Ptype = " String " ){
Params. Sender = $ (Arguments [I]);
If (Params. Sender. Data ( " Isrequesting " ))
Return Null ;
}
Else If (Ptype = " Object " ){
If (Arguments [I]. tagname | Arguments [I]. selector ){
Params. Sender = $ (Arguments [I]);
If (Params. Sender. Data ( " Isrequesting " ))
Return Null ;
}
Else {
Params. Data = Arguments [I];
}
}
}
}
Params. Sender. Data ( " Isrequesting " , True );
Return $. Get (Params. url, Params. Data, Function (Data, status ){
Params. Sender. Data ( " Isrequesting " , False );
If (Data = " Unlogin " ){
Window. Top. Location. href = " /Login. aspx " ;
Return ;
}
If (Params. Callback ){
Params. Callback (data, status );
}
});
},
Postx: Function (){
VaR Params = {URL: URL, data: Null , Callback: Null , Sender: Null };
For ( VaR I = 1 ; I < Arguments. length; I ++ ){
If (Arguments [I] ! = Null ){
VaR Ptype = Typeof (Arguments [I]);
If (Ptype = " Function " ){
Params. Callback = Arguments [I];
}
Else If (Ptype = " String " ){
Params. Sender = $ (Arguments [I]);
If (Params. Sender. Data ( " Isrequesting " ))
Return Null ;
}
Else If (Ptype = " Object " ){
If (Arguments [I]. tagname | Arguments [I]. selector ){
Params. Sender = $ (Arguments [I]);
If (Params. Sender. Data ( " Isrequesting " ))
Return Null ;
}
Else {
Params. Data = Arguments [I];
}
}
}
}
Params. Sender. Data ( " Isrequesting " , True );
Return $. Post (Params. url, Params. Data, Function (Data, status ){
Params. Sender. Data ( " Isrequesting " , False );
If (Data = " Unlogin " ){
Window. Top. Location. href = " /Login. aspx " ;
Return ;
}
If (Params. Callback ){
Params. Callback (data, status );
}
});
}
})
Of course, you can extract a common part or encapsulate the $. Ajax method, but here is just a note...