1

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;

   }

?>

Balakumar B
  • 770
  • 5
  • 17
  • 41
  • Looks like server error. Also $_POST['evnt_id'] should have no value in it and be undefined.. – Massimo Petrus Feb 13 '17 at 05:59
  • where is the closing of your `$('#dynmic_slct').on("change")`? all I can see is closing in your `if statement`. I think it is missing `});` – pryxen Feb 13 '17 at 06:02
  • can you add your `select` tag? – pryxen Feb 13 '17 at 06:06
  • can you check your ajaxRequest.php full path.i think it's ajax request not going on this file – bipin patel Feb 13 '17 at 06:10
  • i have added dynamically in select tag `success: function(reqResult){ var append_string = '
    '+ ''+ '
    '; $('#dynmic_slct').html(append_string); jQuery(".chosen").chosen(); }` @pryxen
    – Balakumar B Feb 13 '17 at 06:12
  • did you wrap your `$('#dynmic_slct').on("change")` in `$(document).ready()`? – pryxen Feb 13 '17 at 06:22
  • yes i have written inside the `$(document).ready()` @pryxen – Balakumar B Feb 13 '17 at 06:26
  • I tested your code, I think your problem is in your Ajax Request – pryxen Feb 13 '17 at 06:31
  • how to fix? because generic request return correct result but company request return parsererror.. i dont understant this bug ? @pryxen – Balakumar B Feb 13 '17 at 06:37
  • your `select[name='company']` is it inside the `#dynmic_slct`? because all I can see is you append your `select[name='generic']` and there is no `select[name='company']` – pryxen Feb 13 '17 at 06:47
  • yes `select[name='company']` inside the `#dynmic_slct`@pryxen – Balakumar B Feb 13 '17 at 06:55
  • Can you remove the `dataType: "JSON",` and try your code again – pryxen Feb 13 '17 at 07:00
  • after romve the dataType, again throw the parsererror!@pryxen – Balakumar B Feb 13 '17 at 07:18
  • i have removed dataType and change php code as follow `echo $template_src = "sample Text";exit;` but i got same error `parsererror`@pryxen – Balakumar B Feb 13 '17 at 07:20
  • check this post @BalakumarB http://stackoverflow.com/questions/5061310/jquery-returning-parsererror-for-ajax-request – pryxen Feb 13 '17 at 07:51

0 Answers0