Reputation: 389
project/add.html:
<input type="text" id="txtmaterialname" class="form-control" name="txtName">
project/assets/js/script.js:
$(document).ready(function() {
$('#txtmaterialname').on('focusout',function(){
var materialname = $("#txtmaterialname").val();
checkmaterial(materialname);
});
});
function checkmaterial(materialname)
{
$.ajax({
url: '../../chk_materialexist.php',
type:'post',
data:{materialname: materialname},
success: function(data){
alert(data);
},
fail: function(xhr, textStatus, errorThrown){
alert('request failed');
}
});
}
project/chk_materialexist.php:
<?php
if(isset($_POST['materialname']))
{
$materialname = $_POST['materialname'];
echo "$materialName";
}
else
echo 'noo';
?>
I'm using Microsoft Edge .. I tried putting an alert
in the script and it worked .. I tried the PHP file and it worked alone but the AJAX request didn't return an answer.
Upvotes: 0
Views: 47
Reputation: 114
The issue here is url: ../../chk_materialexist.php,
. You need to put quotes inside that.
url: '../../chk_materialexist.php',
Upvotes: 2
Reputation: 1075755
$.ajax
doesn't support a fail
option, the option is called error
. (It supports a fail
method on what it returns, but that's different.)
Change fail
to error
.
Upvotes: 2