I want to receive the validate function output in my above PHP code. Except my AJAX, all things are working. Can anyone help me correct the problem?
$(document).ready(function(){
$("#d").click(function(){
validate();
})
function validate() {
var x;
var text;
var y, senddata;
x = document.getElementById('t').value;
y = x.length;
if (isNaN(x) || y < 10 || y > 10) {
document.getElementById('t').style.backgroundColor = "red";
}
// start AJAX in else case to receive validate data
else {
$.ajax({
url: 'json.php',
type: "POST",
dataType:'json',
data: ({ phone: x }),
success: function(response){
alert ("success !");
},
error: function(response){
alert("fail!");
}
});
}
}
});