Jquery ajax complete not getting custom reponse header?
I am trying to pass a custom response header to notify my javascript the user has timed out. It works good expect when it comes to using it with jquery u.i dialogs.
I have this
$.ajaxSetup
({
complete: function (event, xhr, options)
{
if (event.getResponseHeader('X-LOGON') === 'LogOn')
{
window.location.href = "redirect to signin";
}
}
});
So this should run after every jquery ajax request and it does.
Now I have something like this for my dialog
$.manageAjax.add('NonCachedAjaxRequests',
{
type: "GET",
url: 'ajaxRequestPath',
success: function (result)
{
$('#Dialog').html(result).dialog(
{
width: 580,
height: 410,
resizable: false,
modal: true,
buttons:
{
Cancel: function ()
{
$(this).dialog('close');
},
'Create': function ()
{
// create;
}
},
close: function ()
{
//destroy
}
});
}
});
return false;
});
I am using something called ajax manager http://www.protofunc.com/scripts/jquery/ajaxManager/ this just helps with stopping double clicks and stuff like that and uses all the same methods that $.ajax would use.
So now when I look at the request coming back to populate the above dialog box I see this in firebug
Response Headersview source
Server ASP.NET Development Server/10.0.0.0
Date Fri, 02 Jul 2010 22:12:36 GMT
X-AspNet-Version 4.0.30319
X-AspNetMvc-Version 2.0
X-LOGON LogOn
Cache-Control private
Content-Type text/html; charset=utf-8
Content-Length 6468
Connection Close
Notice how it says "X-LOGON" but when it comes to my ajaxSetup and gets to
if (event.getResponseHeader('X-LOGON') === 'LogOn')
it always says it is null but as you can clearly see firebug is saying otherwise. I don't understand whats is going on.
Edit
Ok it seems to be a problem with ajax manager. I really want to keep using it or something comparable as it really helps out with stopping duplicate requests.
What I found out is that it does not like global ajaxSetups I don't know why it just does not like them. I started to try to use status codes instead so I been playing around with "403" and found this.
if an ajax request 403's out and your using ajaxSetup with complete and ajaxmanager it will still try to go into the success message one.
If you put an ajax complete before the success one(it does not work if complete is after success) and it comes back with 403 then ajax manager has no problem acting on it and hitting the complete.
So I am not sure what to do. I want to use ajaxmanager or something like it and I want to use ajaxSetup.
So I don't know if I can have both at this moment though.
Edit 2
When I use status codes and ajaxSetup with ajax manager I get this error
error: status: 403 | URL: /MyURL http://localhost:3086/Plugins/AjaxManager/Source/jquery.ajaxmanager.js Line 44
error: function(ahr, status){
36 var opts = this;
37 if(status && status.indexOf('error') != -1){
38 setTimeout(function(){
39 var errStr = status +': ';
40 if(ahr.status){
41 errStr += 'status: '+ ahr.status +' | ';
42 }
43 errStr += 'URL: '+ opts.url;
44 throw new Error(errStr);
45 }, 1);
46 }
47 },
so I don't know if this is another reason why I am getting an error.
Edit 4
Seems like I been using a version that apparently is not compatable for version 1.4(not sure why it worked)
Anyways I am using 3.0 now it still does not work but it has some new options that I would like to try but have no clue how to use them.
http://www.protofunc.com/scripts/jquery/ajaxManager3/
If you look at the events/callbacks it's got some global complete so maybe that might开发者_Python百科 be what I need. Have no clue how to run it though.
the source code of manageAjax is available here: http://www.protofunc.com/scripts/jquery/ajaxManager/jquery.ajaxmanager.js
The global jquery 'complete' function is sent via those line :
if (opts.global) {
$.event.trigger("ajaxComplete", args);
}
This creates a new Event object on the fly so it blanks out any data you may have available on the original event.
I might be wrong, but after reading the code quickly, the headers are lost early in manageAjax and I am not sure you can do what you want while using this library until the library gets patched to allow this.
So Roberto's comment seems like a good advice : try it without manageAjax and it will most probably work
I hope this will help you,
Jerome Wagner
精彩评论