I have a little script which demonstrates my problem, here is javascript code of test.html page
<script>
function test(e) {
if(e < 2) {
return;
} else {
return $.ajax({
type: "POST",
url: "test.php",
data: {
e: e
},
success: function (data) {
alert(data);
}
});
}
}
$(document).ready(function () {
$(document).on("click", "#bth", function () {
test(1).done(function () {
alert('done');
});
});
});
</script>
and
<body>
<input type="button" id="bth" value="OK" />
</body>
in test.php I put
<?php echo $_POST['e']; ?>
I got javascript error at this line: test(1).done(function(){
If argument is more than one (for example test(2)) it works fine.
How can I solve this problem?
If
e < 2, your function doesn’t return anything.You can’t call
.done()onundefined.Instead, you can return a pre-resolved deferred object: