jquerypostiframecolorbox

Posting data to a colorbox iframe?


Here is the code I'm working with. From other examples I've seen, this should work but it is not. And have already made sure that I am using the latest colorbox.

function updateFolderCate(ID,Type){
    $.colorbox({
        iframe:true,
        scrolling: false,
        innerWidth:'100',
        innerHeight:'100',
        href:"page.php",
        data:{LinkID:ID,itemType:Type},
        onClosed:function(){
            //Do something on close.
        }
    });
}

Solution

  • You are setting iframe to true. What this does is opens a colorbox, creates an iframe, and sets the src attribute of the iframe to the location specified by href. So logically this can't do POST requests. This might accomplish what you want but I'm not sure.

    function updateFolderCate(ID,Type){
        $.colorbox({
            open: true,
            scrolling: false,
            innerWidth:'100',
            innerHeight:'100',
            href:"page.php",
            data:{LinkID:ID,itemType:Type},
            onClosed:function(){
                //Do something on close.
            }
        });
    }
    

    This isn't going to behave exactly like the iframe method does, you may have to rework your endpoint. If your endpoint doesn't HAVE to only receive POST requests then go with earlonrails' answer.

    EDIT: I came to this after diving the source code: Source

    The relevant lines are line 800 and line 856. iframe and href didn't seem compatible, so then I inspected the element that was loaded in Firebug and noticed it was an iframe with the src attribute set to the href variable.