framework7

Open full view…

Ajax Form submit Twice?

Lim Heng Cheun
Wed, 25 Jun 2014 09:02:09 GMT

Hi, I found out when I using ajax-submit method it will automatically submit twice, is it I doing something wrong? <div class="views"> <div class="view view-main" data-page="home"> <div class="pages"> <div data-page="home" class="page toolbar-fixed"> <div class="toolbar tabbar tabbar-labels"> <div class="toolbar-inner"> <a href="#tab1" class="tab-link active"> <i class="icon login-icon"></i> <span class="tabbar-label">Login</span> </a> <a href="#tab2" class="tab-link"> <i class="icon register-icon"></i> <span class="tabbar-label">Register</span> </a> </div> </div> <div class="page-content"> <div class="content-block"> <div class="tabs"> <div id="tab1" class="tab active"> <div class="list-block"> <form action="http://www.xxx.com/login" method="POST" id="login-form" class="ajax-submit"> <ul> <li> <div class="item-content"> <div class="item-media"><i class="icon icon-form-email"></i></div> <div class="item-inner"> <div class="item-title label">E-mail</div> <div class="item-input"> <input type="email" name="email" placeholder="E-mail"> </div> </div> </div> </li> <li> <div class="item-content"> <div class="item-media"><i class="icon icon-form-password"></i></div> <div class="item-inner"> <div class="item-title label">Password</div> <div class="item-input"> <input type="password" name="password" placeholder="Password"> </div> </div> </div> </li> <li> <div class="item-content"> <div class="item-inner"> <input type="submit" value="Submit" class="button button-big button-submit"> </div> </div> </li> </ul> </form> </div> </div> <div id="tab2" class="tab"> <p>Tab 2</p> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse at nibh felis. Nunc consequat diam et tellus tempor gravida. Donec hendrerit aliquet risus, ut tempor purus dictum sit amet. Integer sit amet lacus eget ipsum pulvinar interdum. Proin semper turpis sed placerat dapibus. Sed iaculis id nibh a viverra. Sed vitae tellus sed purus lacinia dignissim. Aenean sagittis interdum leo in molestie. Aliquam sodales in diam eu consectetur. Sed posuere a orci id imperdiet.</p> <p>Donec et nulla auctor massa pharetra adipiscing ut sit amet sem. Suspendisse molestie velit vitae mattis tincidunt. Ut sit amet quam mollis, vulputate turpis vel, sagittis felis. Vestibulum ornare ut eros vitae adipiscing. Vestibulum volutpat justo enim, ullamcorper vulputate sapien lacinia vel. Integer sed justo ultrices augue tincidunt dictum eu vel orci. Mauris sodales auctor diam vel condimentum.</p> <p>Praesent mauris purus, faucibus vel hendrerit at, dapibus quis lorem. Sed placerat fermentum blandit. Suspendisse potenti. Cras sollicitudin laoreet tellus, ut gravida leo eleifend convallis. Sed pharetra nisl quis libero fermentum pharetra. Cras lacinia quam turpis, eget varius risus interdum sit amet. Quisque laoreet tortor dui, vitae accumsan lacus fringilla in. Quisque consequat placerat risus, non ornare felis scelerisque quis. Sed adipiscing diam tellus, vel faucibus mauris rhoncus vel. Vestibulum eu ultrices tortor, non suscipit lorem. Mauris tellus nulla, volutpat quis lacus eu, scelerisque adipiscing dui. Nullam nec tempor sem, nec pulvinar sapien. Etiam blandit condimentum vehicula.</p> <p>Praesent nec imperdiet diam. Maecenas vel lectus porttitor, consectetur magna nec, viverra sem. Aliquam sed risus dolor. Morbi tincidunt ut libero id sodales. Integer blandit varius nisi quis consectetur. Nulla pellentesque elementum ligula vitae porta. Nunc sollicitudin mi quis mi mattis cursus. Nulla diam felis, ullamcorper eget lacinia ac, auctor id velit. Fusce enim nunc, egestas a augue vitae, malesuada tincidunt risus. Nullam fringilla, enim nec porta iaculis, enim leo pharetra nunc, eget rutrum tortor dui et risus. Etiam sit amet molestie dolor. Curabitur ultrices justo ut augue ornare, vel pharetra libero adipiscing. Duis rhoncus a felis ac venenatis. Duis posuere non leo vitae tincidunt. Integer luctus arcu ut risus posuere, vel vehicula ipsum elementum. Duis et cursus sapien. </p> </div> </div> </div> </div> </div> </div> </div> </div> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/phonegap.js"></script> <script type="text/javascript" src="js/framework7.min.js"></script> <script type="text/javascript" src="js/my-app.js"></script> <script> document.addEventListener('deviceready', this.onDeviceReady, false); function onDeviceReady() { navigator.splashscreen.hide(); } var myApp = new Framework7(); var $$ = Framework7.$; $$('#login-form').on('submitted', function (e) { var data = e.detail.data; // Ajax repsonse from action file console.log(data); if(!$.isNumeric(data)) { myApp.alert(data,''); } else { console.log('success'); } }); </script>

Vladimir Kharlampidi
Wed, 25 Jun 2014 16:38:36 GMT

So you have 'success' 2 times in console after submit? Need to check it

Lim Heng Cheun
Thu, 26 Jun 2014 05:56:51 GMT

Hi, fail or success also two time

Vladimir Kharlampidi
Thu, 26 Jun 2014 20:25:54 GMT

Hmm, what i already have not tried, but i can't replicate your issue. But it could happen only if you attach this event listener two times. What i see in your code you have attached my-app.js and then <script> tag with your code example. Are not have the same code in both my-app.js and plain <script> tag after that?

Lim Heng Cheun
Fri, 27 Jun 2014 03:04:25 GMT

Ok thx i deleted var myApp = new Framework7(); var $$ = Framework7.$; in my script then fixed the problem.=)