I came across the problem of headers when porting an application to jQuery. The header call gives an error and halts the process due to headers already sent error, and after a while of Google searching I didn't really come up with much but a few people asking the question with no real answers. (at least none that suited me) So, how do you handle a load that your PHP may try to redirect with a header call?? Well, here is what I did...I duplicated the standard load function and created a loadphp one. This one generates a hidden iframe, loads the content, then ports it back into the element that called it in the first place. This works for me (in my environment), so no guarantees that it will work for you, but I found it helpful so figured I would share.
I can now redirect to my hearts content using PHP.
Also, I was able to use it in case my PHP session timed out on me and redirected to my login page. In my login page I can look to see if its TOP, and if not force it out of the IFRAME.
Of course, must be on same domain only.
jQuery.loadphp.js
//######
//## Modified jQuery Load to handle PHP header redirects
//## Tyler Boyd, 2010
//######
jQuery.fn.extend({
loadphp: function( url, params, callback ) {
if ( typeof url !== "string" ) {
return _load.call( this, url );
// Don't do a request if no elements are being requested