I have written Jquery Ajax call but i got Parsererror.. in following js code i have checked which select element is changed in dynamic_slct
. and i have checked generic or Company and then call GnrtTemp()
with pass selected Element value.. if I select generic my follwing Code(function GnrtTemp and ajax call) is working.. if i select company i got Error parsererror.. my doubt is same ajax call working Generic and is not working as company.. what is the problem? How to fix that problem i have attached my js code and also PHP code .. If i did any mistake pls correct me.. suggest to solution.?
JS
$('#dynmic_slct').on("change", "#master ,select[name='company'], select[name='generic']", function(element){
if(element.target.name == 'generic' || element.target.name == 'company') {
GnrtTemp(element.target.value);
}
});
function GnrtTemp(id){
$.ajax({
method: "POST",
url: "ajaxRequest.php",
dataType: "JSON",
data: {fn: "getTemp", id: id},
success: function(reqResult){},
complete: function (jqXHR, textStatus) {
alert(textStatus);
}
});
}
ajaxRequest.php
<?php
$finalRes = array();
if($_POST['fn'] == 'getTemp'){
$template_src = getTemp($_POST['id']);
$finalRes['result'] = $template_src;
echo json_encode($finalRes);
}
function getTemp($id){
$db = new DB();
$Query = "SELECT template_src
FROM master
WHERE refid =$id";
$qryRes = $db->query($Query);
return $qryRes;
}
?>