Javascript x Ajax x html x jquery

1

Please, I need some help. I'm trying to develop an application with phonegap x jquery / strong> Ajax and I have the following situation:

I'm on a page, after the user enters an email and password, I call ajax , from an external page to validate, in js . As below:

Item 1:

$('form').submit(function() {    
console.log( "submit!" );
var postData = $(this).serialize();
$.ajax({
        type: 'POST',
        data: postData,
        url: 'http://localhost/service/service_usu.php',
        success: function(data){
            //alert('ret:'+data);
                if (data!='11') {
                    //alert('usuario nao validado!');                               
                    window.location='http://localhost/usu_incons.html';
                }           
                if (data=='11') {
                    alert('usuario validado!');
                    //window.location='http://localhost/inc_usu_ok.html';
                }           
        },
        error: function(){
            //console.log(data);
            alert('There was an error adding your comment');
        }
    });
    return false;
});

Perfect, checks the user and when negative calls the page usu_incons.html , and on this page shows the reason for the inconsistency and has a back button: <a id="voltar" href="index.html" data-role="button">Usu&aacute;rio ou email inexistente!</a>

Perfect, it returns to the index.html page. On this page index.html the javascript button of item 1 above does not work anymore, I already tried item 3 below and nothing .... ... I do not know what to do so you can re-enter the email and password and call the js / ajax > again.

item 3:

$(document).ready(function(){
  app.initalize;
  app.receivedEvent;
  console.log( "ready!" );
});
var app = {

        initialize: function() {
            this.bindEvents();
            //console.log( "entrou initialize" );
        },

        bindEvents: function() {
            document.addEventListener('deviceready', this.onDeviceReady, false);
            $(document).on("pagecontainershow", app.onDeviceReady);
        },

        onDeviceReady: function() {
            app.receivedEvent('deviceready')
        },

        receivedEvent: function(id){

            alert($.mobile.pageContainer.pagecontainer('getActivePage').data('http://localhost/usu_incons.html'));

        }

}
    
asked by anonymous 03.09.2015 / 05:16

1 answer

1

Try the following

Include in the submit button a touch / click action, execute this at the time of "deviceready"

//exemplo
jQuery("#id_do_submit").on("click",function(e){
    e.preventDefault(); //para evitar que execute algo...
    //seu código aqui
});

With this you ensure that every time the button is clicked an action will be executed.

Of course you need to take care not to run multiple times in case a user presses the button repeatedly ...

^^ V

    
03.09.2015 / 06:35