Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $("#btn_go").on('click', function(){
- if(validateUserDetails() == false){
- return;
- }
- });
- function validateUserDetails(){
- var bool = false;
- $.ajax({
- url: 'response.php?type=validateUserDetails',
- type: 'POST',
- dataType: 'json',
- data: {name: $("#checkout_name").val(), email: $("#checkout_email").val(), "country": $("#checkout_country").val(),
- "city": $("#checkout_city").val()},
- success: function(data){
- console.log(data); // this is currently returning FALSE
- // Which is totally correct!
- if(data == true){ bool = true; }
- return trueOrFalse(bool);
- }
- });
- }
- function trueOrFalse(bool){
- return bool;
- }
- function validateUserDetails(){
- return $.ajax({
- url: 'response.php?type=validateUserDetails',
- type: 'POST',
- async: false,
- dataType: 'json',
- data: {name: $("#checkout_name").val(), email: $("#checkout_email").val(), "country": $("#checkout_country").val(),
- "city": $("#checkout_city").val()},
- success: function(data){
- console.log(data); // this is currently returning FALSE
- }
- });
- $("#btn_go").on('click', function(){
- validateUserDetails().done(function(data){
- if(data == "someValue")
- return "whatever you want";
- }
- });
- function validateUserDetails(){
- // asynchronous function
- $.ajax({...});
- return undefined;
- }
- function validateUserDetails() {
- var bool = false;
- $.ajax({
- url: 'response.php?type=validateUserDetails',
- type: 'POST',
- async: false,
- dataType: 'json',
- data: {name: $("#checkout_name").val(), email: $("#checkout_email").val(), "country": $("#checkout_country").val(), "city": $("#checkout_city").val()},
- success: function(data) {
- console.log(data); // this is currently returning FALSE
- // Which is totally correct!
- if (data == true) {
- bool = true;
- }
- }
- });
- return trueOrFalse(bool);
- }
- function validateUserDetails() {
- var deferred = $.Deferred();
- var bool = false;
- $.ajax({
- url: 'response.php?type=validateUserDetails',
- type: 'POST',
- dataType: 'json',
- data: {name: $("#checkout_name").val(), email: $("#checkout_email").val(), "country": $("#checkout_country").val(), "city": $("#checkout_city").val()},
- success: function(data) {
- console.log(data); // this is currently returning FALSE
- // Which is totally correct!
- if (data == true) {
- bool = true;
- }
- }
- complete: function () {
- deferred.resolve(trueOrFalse(bool));
- }
- });
- return deferred.promise();
- }
- function test() {
- var promise = validateUserDetails();
- promise.done(function(result) {
- console.log("Bool: " + result);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement