user3817083
user3817083

Reputation: 79

Ajax Not Loading PHP

I'm trying to load a PHP file into another PHP file on a click event through Ajax. I'm trying to do this to eliminate loading several modals I have on the page. It seems the PHP file is loading (in the console), but nothing is showing up.

Here's my javascript:

    $("a#lightbox-open").click(function(e){
    e.preventDefault();
    $("body").addClass("noscroll");
    $('section#lightbox').addClass("open");
    $.ajax({
        context: '#lightbox-holder',
        url: '/template/lightbox.inc.php',
        type: 'POST',
        dataType: "json",
        success: function(html){
            alert("works");
        }
    });
});

In my main PHP file, I have a div #lightbox-holder that lightbox.inc.php is supposed to load into it.

Upvotes: 0

Views: 52

Answers (1)

kero
kero

Reputation: 10638

context expects a (Plain)Object (as you can read in the api doc). Replacing '#lightbox-holder' by $('#lightbox-holder') will do the trick.

Working fiddle with the $() added versus non working fiddle representing your current code.

Upvotes: 1

Related Questions