afarkas / ajaxmanager Goto Github PK
View Code? Open in Web Editor NEWAn jQuery Plugin, wich helps you to manage AJAX requests and responses (i.e. abort requests, block requests, order requests)
An jQuery Plugin, wich helps you to manage AJAX requests and responses (i.e. abort requests, block requests, order requests)
Hi
I am wondering how do you use ajax manager with deferred ajax that came out with the release of jquery 1.5?
Thanks
Hi
I am using Ajaxmanager with uniqueName and I am wondering how to use these enhanced callbacks
for instance how do I use
managerName + 'AjaxStart' (global) event new
would it be
$.manageAjax.AaxStart({ ... });
Does this override the jquery AjaxStart?
In IE6 I have "null or not an object error" when cacheResponse=true.
Go to your site http://www.protofunc.com/scripts/jquery/ajaxManager/ and click the laste example.
Note: getAllResponseHeaders was introduced in Windows Internet Explorer 7.
I guess it would be enough to just disable functions for old browsers.
Hi ,
Iโm using the ajaxmanager, it is very help for me, thank you very much.
When I use it found below things, I appreciate if you can consider them and make some change in next version.
In this function will call $.dequeue first then call inprogress--;
And $.dequeue will execute a _createAjax function to increase the inprogress.
If lots of ajax in the queue then will keep increase inprogress untill no ajax in the queue then
_removeXHR got chance to call inprogress--;
Idealy if 5 ajax in the queue, the inprogress should change as 1 0 1 0 1 0 1 0 1 0
But now inprogress change as 1 2 3 4 5 4 3 2 1 0
*I thinks should call inprogress--; before call $.dequeue
2. getData function
in this function got below condition Got below condition
if(!ret && this.opts.queue)
is it necessary to use this.opts.queue ?
Sometime I need change the queue as false for a while,if I do so the abort function can not work because this getData function can not return the right function
*I thinks maybe can remove && this.opts.queue
3._createAjax function
In this function if(o.cacheResponse && cache[id]) it will simulate the ajax success and complete
I think if o.beforeCreate return false also need simulate the complete function
So that we can got a chance to do something in that function when beforeCreate return false
4.actually what I really need is a gap between ajax functions
now if lots of ajax in the queue already, the script will keep dequeue and process the ajax, then the UI got no chance to process other tasks(like detect user action or show some animation) so the the page performance will not good.
so i think it is better if have a gap after one ajax complete to release the CPU for other tasks
My issues quite messy hope you can understand what i want to say.
again thank you for you provide so good plugin.
Hi
I am using jquery 1.7.1 and ajax manager 3.12 and I can't get the preventDoubbleRequests to work.
I have
$.manageAjax.create('Test',
{
preventDoubbleRequests: true,
cacheResponse: false
});
$.manageAjax.add('Test',
{
type: 'Post',
data: frm,
url: "URL',
success: function (response)
{
}
});
Yet I spam as many times as I want and it will keep posting. I asked someone else to try it as well and they get the same problem. Can you verify if I am doing anything wrong?
Thanks
Playing around with the script i found an error occuring sometimes:
uncaught exception: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: http://192.168.161.100/js/jquery/jquery.ajaxmanager.js :: anonymous :: line 80" data: no]
which refers to this line:
var httpStatus = ahr.status,
According to this page it is not allowed to direclty read the .status value:
http://helpful.knobs-dials.com/index.php/%22Component_returned_failure_code:_0x80040111_%28NS_ERROR_NOT_AVAILABLE%29%22
(needs try/catch block as it seems, but i don't really know for sure).
PS: Adding the try{}catch(err){} block will then throw the timeout error which should be correct.
Can't say for sure since i'm on vacation right now, but the other day when i implemented ajaxmanager 3.0 with jquery 1.5.1 nothing worked, i got some error about "label something" (they did rewrite the whole ajax pipeline tho), when i switched back to jquery 1.4.4 everything worked again.
Sorry for the vague information...
Robert
var ManagedAjax = $.manageAjax.create('Queue', { queue: true, maxRequests: 2, cacheResponse: false });
function requestajax(){
ManagedAjax.add({
async: false,
url: "ajax_request.php"
});
}
Will only execute the Ajax Request once.
(Tested with JQuery 1.4.2, FireFox 3.6.2, Firebug, Fedora12)
I am using JQuery 1.5.1 with the latest copy of Ajaxmanager, version 3.11 (the commit comments say "simple jquery 1.5.1 compatibility").
When making request with the option { dataType: "json" }, I get an error. In Firefox, the error says "Invalid label" and in Chrome, it says, "Uncaught SyntaxError: Unexpected token :".
It looks like this error is related to extending/overriding $.ajaxSettings. If I change this line of code:
this.opts =
To this:
this.opts =
Then the error goes away.
It looks like the new way of implementing this type of functionality is to use prefilters. The JQuery validation plugin was throwing similar errors and they released a fix using the new prefilter callbacks. Here are the related docs.
http://api.jquery.com/extending-ajax/
I don't understand the problem well enough to submit a patch, so I hope this is enough information to identify the problem and I'm hoping there is an easy fix for future releases.
A temporary fix is to use the option { dataType: "text json" }. This seems to correct for the problem.
Hi! Could you possibly update the source to be JSLint Compliant?
http://jslint.com/
Formatting it correctly beforehand helps a bit:
http://jsbeautifier.org/
Unless you disagree with both these tools, though I'd be curious as to why if you did :)
Thanks!
-Kyle
Problem is in _createAjax method:
_createAjax: function(id, o, origSuc, origCom){
var that = this;
return function(){
if(o.beforeCreate.call(o.context || that, id, o) === false){return;}
that.inProgress++;
if(that.inProgress === 1){
$.event.trigger(that.name +'AjaxStart');
}
if(o.cacheResponse && cache[id]){
if(!cache[id].cacheTTL || cache[id].cacheTTL < 0 || ((new Date().getTime() - cache[id].timestamp) < cache[id].cacheTTL)){
that.requests[id] = {};
//START OF TWEAK
var cachedData = cache[id];
//END OF TWEAK
setTimeout(function(){
that._success.call(that, o.context || o, origSuc, cachedData._successData, 'success', cachedData, o);
that._complete.call(that, o.context || o, origCom, cachedData, 'success', id, o);
}, 0);
} else {
delete cache[id];
}
}
if(!o.cacheResponse || !cache[id]) {
if (o.async) {
that.requests[id] = $.ajax(o);
} else {
$.ajax(o);
}
}
return id;
};
}
When calling method clearCache just in time when setTimeout defers funtion invocation I had "undefined" issue with cache[id] because cache was meanwhile cleared. Fix is very easy and is surrounded by commentaries:
//START / END OF TWEAK
Hi
I am wondering is it possible to use ajax manager with the form plugin? I need to upload a file(what ajax can't handle). So I need something like http://malsup.com/jquery/form/#file-upload
Yet it just users the ajax object. I would like to still keep using your plugin as I want to use features like prevent duplicate upload.
Shouldn't it be preventDoubleRequests
? It seems like the typo is made both in the source code and the documentation
Though it seems logical is some situations it complicates business logic counting on data in XHR object. For example if someone checks xhr.status in success callback, or examines response headers. I've prepared patch where object imitating is cached along with the data - callbacks can then examine the XHR the same as original XHR in no cached situation.
Hi
See this post. http://stackoverflow.com/questions/3169419/jquery-ajax-complete-not-getting-custom-reponse-header
You also really need to add some examples on how use these new call backs like the global ones I have no clue how to get them to work and I been trying for like 2 hours.
Hi
I did this
$('#Id').live('click', function ()
{
/* Ajax request to load form into it */
var manager = $.manageAjax.create('nonCachedAjaxRequests',
{
preventDoubbleRequests: true,
cacheResponse: false
});
manager.add
({
type: 'Get',
url: 'url here',
success: function (response)
{
// stuff here
}
});
});
However when I do a double click it still allows them to go through however when I use the other way(uniqueName) It all works.
Stuff like caching seem to work just the preventDoubbleRequests is having problems.
this pluggin throws error when tried to get jsonp with cacheResult=true
eg:
var options = {
url: 'http://gdata.youtube.com/feeds/api/videos',
type: 'get',
cache: false,
data: {
q: 'india',
alt: 'json-in-script',
'max-results': 10,
format: 5,
'start-index': 1,
orderby: 'published'
},
dataType: 'jsonp',
success: function (data) {
if (console) {
console.log('data received');
}
}
};
var someManagedAjax = $.manageAjax.create('someAjaxProfileName', { queue: true, cacheResponse: false,cacheTTL:7000 });
someManagedAjax.add(options);
cacheResponse=true: will throw error
cacheResponse= false: would not
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.