Home Return true/false on submit button click, based on ajax response
Reply: 0

Return true/false on submit button click, based on ajax response

user1044
1#
user1044 Published in June 20, 2018, 1:28 am

Based on some JSON I recieve from an ajax request, I wish to either allow or deny a submit button press (return true/false).

I've attempted to implement a promise, however, I can still see 'product unavailable' is called before I recieve my ajax response.

Is the issue down to it being a form/submit button? Or is this still possible?

var oAH = {

    ValidateSubmit : function(self){

        // send request to handler
        $.ajax({
            type: "POST",
            url: "",
            data: aData,
            cache: false})
        .done(function(data) {

            var oJSON = JSON.parse(data);
            if(oJSON.Status === 1){
                // return true to allow form to submit
                return true;
            }else{
                console.log('product unavailable (error message)');
                return false;
            }
        })


    }
}


// click handler
$('#submitButton').on('click', function(){
    return oAH.ValidateSubmit(this);
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.331628 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO