weixin_33713350 2016-03-11 00:24 采纳率: 0%
浏览 35

Ajax未加载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.

  • 写回答

1条回答 默认 最新

  • weixin_33674437 2016-03-11 00:48
    关注

    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.

    评论

报告相同问题?