79340

Fancybox v2.1.3 ajax load form

Question:

Hi again to all fancybox lovers. I got stuck with ajax load an external html form into current viewed html file. I use a hidden trigger with class="fancybox.ajax" in a tag that is brought into html that way:

$('body').prepend('<a class="fancybox fancybox.ajax" href="form.html" style="display: none;"></a>');

so that form can be brought next with following into html:

$(".fancybox.ajax").trigger('click');

But this fails. Maybe i need "on" or "live". I do not know if there is a better way to achieve this. Then i want to make some js checks over form submission but how this will run? Maybe some good use of "on"

$('#submit').on(click, function({ .... }));

Any help will be much appreciated.

Answer1:

Rather try

$(".fancybox").trigger('click');

... the class fancybox is used to bind such selector to fancybox while the fancybox.ajax class is used to define the type of content (you don't need to use live since fancybox v2.x already uses that method)

On the other hand, if you want to perform some actions on form submit, try binding the .on() method to the form selector (not the submit button) like

$('#formSelector').on("submit", function({ //do somthing }));

Answer2:

Ok the answer to submit the form that is brought with ajax is only

$("#submit").live('click', function() { ... });

till now, i could not make on() to work by no means.

Recommend

  • insert element in the dom using javascript or jquery
  • Transfer learning/ retraining with TensorFlow Estimators
  • how can i reference $_SERVER['DOCUMENT_ROOT'] in a .htaccess file?
  • can an element have a a decimal height in html/css?
  • How can I specify an auto_prepend_file in my .htaccess file without hardcoding the absolute path?
  • C++ development on linux Code::Blocks, EMACS or GVIM [closed]
  • Getting the width from an scaled image
  • C# COM Component Fails To Read Config When Loaded Into An Unmanaged C++ App
  • Bootstrap Popover showing at wrong place upon zoom in/out or resizing Browser window
  • ASPNetCore MVC Routing Let Server Handle Specific Route
  • how to get data attributes of dynamically generated element
  • npm 5.4.1 install/uninstall all failing
  • Simulate click Geckofx vb,net
  • Position: fixed nav does not stay fixed
  • Button text different than value submitted in query string
  • Alternative To body {overflow:scroll;} That Will Prevent Page Jostling/Wriggling?
  • How do I pass the string value parameter of the selected list item from an auto-populated dropdown l
  • Play WS (2.2.1): post/put large request
  • OpenGL 3.3 on Mac OSX El Capitan with LWJGL
  • Jquery UI tool tip close icon
  • Get one-time binding to work for ng-if
  • Why ng-show works with ng-repeat but ng-if doesn't? [duplicate]
  • HTML download movie download link
  • Volley JsonObjectRequest send headers in GET Request
  • Running a C# exe file
  • Importing jscolor library in angular 2
  • jquery mobile loadPage not working
  • Warning: Can't call setState (or forceUpdate) on an unmounted component
  • Cannot Parse HTML Data Using Android / JSOUP
  • Data Validation Drop Down Box Arrow Disappearing
  • How do you join a server to an Active Directory (domain)?
  • Java static initializers and reflection
  • unknown Exception android
  • Easiest way to encapsulate a HTML5 webpage into an android app?
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Unable to use reactive element in my shiny app
  • java string with new operator and a literal