1

I want to pop up the ajax response by fancybox, I saw the network section in console, the response is ok. But I am getting $.fancybox is not a function. thanks in advance!

$("#mysubmit").click(function(){
 var myvar = {
"secure_key":"41561541561561","username":$("#username").val(),"password" :$("#password").val()};

$.ajax({

    type: "POST",
    url: "http://127.0.0.1/ajaxtest.php",
    async: false,
    data: myvar,
    success: (function (response) {
        var result =
            "<div id='result'>" +
            "<p>" + response + "</p>" +
            "</div>";
        //$.facybox is not a function HERE
        $.fancybox(result, {
            type: "html",
        }); // show formated response
      })
   })

});
Nima
  • 3,309
  • 6
  • 27
  • 44
Zain Deeb
  • 39
  • 8

2 Answers2

0

FancyBox has to be instanciated on an element.
You actually try to instanciate it on jQuery...

Try this:

success: (function (response) {
  var result =
    "<div id='result'>" +
    "<p>" + response + "</p>" +
    "</div>";

  $("body").append( $(result) );

  $(document).find("#result").fancybox(); // show formated response
})
Louys Patrice Bessette
  • 33,375
  • 6
  • 36
  • 64
0

in case if anyone searching for the same problem, here is the solution:

$("#mysubmit").click(function(){
var myvar = {
"secure_key":"41561541561561","username":$("#username").val(),"password" :$("#password").val()};

 $.ajax({

    type: "POST",
    url: "http://127.0.0.1/ajaxtest.php",
    async: false,
    data: myvar,
    success: (function (response) {
      var result =
        "<div id='result' style='display: none;'>" +
        "<p>" + response + "</p>" +
        "<a class='btn' data-fancybox-close=''>OK!</a>"+
        "</div>";

      $("body").append(result);
    })
})

});

and then I added the #result as a data-scr to tag, works perfectly.

<a data-fancybox type="Submit" id="mysubmit" class="btn" data-src="#result" >Submit </a>
Zain Deeb
  • 39
  • 8