This question already has an answer here:
I have two functions in javascript to check the code if it exist in database. I just wonder why my codeChecker function does not return anything? It suppose to return a number this is my code Im so confused.
$('#generateCoupon').on('click', app.generateCouponCode);
generateCouponCode: function() {
var couponInput = $('#couponName');
var checker = '';
couponInput.val('');
var code = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
do {
for( var i=0; i < 10; i++ )
code += possible.charAt(Math.floor(Math.random() * possible.length));
var checker = app.codeChecker('UU9CH0IQ1X'); // Test value loop should not be end because this value is already on Database
alert(checker); // Test ALERT return nothing
} while (checker > 0);
couponInput.val(code);
},
codeChecker: function(code) {
var check;
$.get("/api/check-code",
{ code: code },
function (data) {
check = data;
}
);
return check;
},
My controller:
public function checkCouponCode()
{ $code = Input::get('code');
$model = Coupon::where('code', $code)->get();
return Response::make(count($model));
}
Why codeChecker return nothing? The loop should never end because the value I passed to codeChecker is already on database. Im so confused I dont know what's wrong. I just do this to test if the checker is doing good. Thanks.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire