Ajax on facebox

52 views
Skip to first unread message

Tommy Bustomi

unread,
Mar 24, 2018, 5:15:41 AM3/24/18
to facebox
Hi everyone



=== index.php ===

<!DOCTYPE html>
<html>
      <head>
            <script src="jquery.js" type="text/javascript"></script>
            <link href="/facebox/facebox.css" media="screen" rel="stylesheet" type="text/css"/>
            <script src="/facebox/facebox.js" type="text/javascript"></script>
            $(document).ready(function() {
                  $('a[rel*=facebox]').facebox({
                        loadingImage : '<?=base_url().JS?>facebox/loading.gif',
                        closeImage   : '<?=base_url().JS?>facebox/closelabel.png'
                  });
                  $('#myform').submit(function(event) {
                        $.ajax({
                              type : 'POST',
                              url   : 'process.php';
                              data : {'name' : $('input[name=name]').val(),'email' : $('input[name=email]').val()},
                              success:function() {
                                   alert('success!');
                              },
                        });
                        event.preventDefault();
                  });
            }); 
      </head>
      <body>
            <a href="http://domain.com/showform.php" rel="facebox">Show Form</a>
      </body>
</html>

==== showform.php ====
<form action="process.php" id="myform" method="post" accept-charset="utf-8">
<input type="text" name="name" placeholder="Your Name" >
<input type="email" name="email" placeholder="Your Email" >
</form>


The problem is the AJAX doesnt work. I guess the problem is failed calling  the selector #myform 

Any help on that is very appreciated!
Thanks




Israel Carberry

unread,
Mar 25, 2018, 10:13:29 AM3/25/18
to facebox
Your JS needs to be wrapped in <script> tags.
Reply all
Reply to author
Forward
0 new messages