CodeIgniter Forums
No value in the call back - Jason - Jquery - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: No value in the call back - Jason - Jquery (/showthread.php?tid=57197)



No value in the call back - Jason - Jquery - El Forum - 02-25-2013

[eluser]Shiju S S[/eluser]
I have a script that executes on onchange
Code:
<$cript>
var base_url = "&lt;?php echo base_url();?&gt;";
var getValues = function(el, callback)
{
  //callback([{ text : 'test', value : 'test1'}]);
  $.ajax({
  type: "POST",
  url: base_url + "franchisee_lab_investigations/get_patient_details",
  dataType: "jason",
  data: {fields:$("#tags").val()},
  success: function(data) {
    callback(data);
  }
   });

};

$('#tags').change(function()
{
    $('#tags').css('color', '#900');
var output = getValues(this, function () {
  alert(output);
});
  
});
</$cript>

Input tag:
<div class="ui-widget">
&lt;input id="tags" name="textPatientname" class="inp-form" type="text"
placeholder="Search Patient Name or ID..." required &gt;
</div>
Controller

Code:
public function get_patient_details()
{
  $searchterm  = $this->input->post('fields'); // fields comes from ajax
  $franid=$this->session->userdata('franid');

  $data="";

     $query ="SELECT DISTINCT c_patient_name FROM patients_master  order by c_patient_name desc LIMI 1";  

  $result = $this->itc_db->get_results($query);

  if($result)

  {

   foreach($result as $row):

   $data[] = array('id' => $row->c_patient_name, 'label' => $row->c_patient_name, 'value'=> $row->c_patient_name);

    endforeach;    

  }  
  echo json_encode($data); // returns data to the search box
}
I am not getting any value for the var output.


No value in the call back - Jason - Jquery - El Forum - 02-25-2013

[eluser]Otemu[/eluser]
You gave me a chuckle with this, set your data type to Json not dataType: "jason",


No value in the call back - Jason - Jquery - El Forum - 02-25-2013

[eluser]Shiju S S[/eluser]
dataType: "json",

Still not working. I was trying different things that is why the error came in the posting.


No value in the call back - Jason - Jquery - El Forum - 02-25-2013

[eluser]Shiju S S[/eluser]
I tried this, but no result.
Code:
<$cript>
var base_url = "&lt;?php echo base_url();?&gt;";
$('#tags').change(function()
{
    $('#tags').css('color', '#900');
  $.getJSON( base_url + "franchisee_lab_investigations/get_patient_details", function(data) {
  for (var i in data)
  {
   alert(data[i].ThreadID);
  }
});  
  
});
</$cript>



No value in the call back - Jason - Jquery - El Forum - 02-25-2013

[eluser]Otemu[/eluser]
When you access the url directly www.yoursite.com/franchisee_lab_investigations/get_patient_details do you recieve a JSON result?
Have you tried using GET instead of POST?


No value in the call back - Jason - Jquery - El Forum - 02-25-2013

[eluser]Shiju S S[/eluser]
Code:
<$cript>
var base_url = "&lt;?php echo base_url();?&gt;";
$('#tags').change(function()
{
var jqxhr = $.getJSON(base_url + "franchisee_lab_investigations/get_patient_details", function(data) {
  alert(data);
})

});
</$cript>

I get an output object object


No value in the call back - Jason - Jquery - El Forum - 02-25-2013

[eluser]CroNiX[/eluser]
instead of
alert(data)
try
console.log(data)
and then look at the built in js console in your browser.

Also, you are using json_encode() to send the json, but you don't seem to be sending json headers, so the json is probably getting sent with an html header.


No value in the call back - Jason - Jquery - El Forum - 02-26-2013

[eluser]Shiju S S[/eluser]
There was two errors;
1. In the controller ( Select query). After that I got the success message from getJSON.
2. Second was in getting the correct index for the parameter data.

Regarding the headers and log console as explained by one of the member, I have lesser idea and have to workout.
Thanks for the help.

Correct code is given below.
Code:
&lt;!-- onchange patient name field --&gt;
<$cript>
var base_url = "&lt;?php echo base_url();?&gt;";
$('#textPatientage').focus(function()
{
var key = $('#tags').val();
var jqxhr = $.getJSON(base_url + "franchisee_lab_investigations/get_patient_details/" + key, function(data) {
  $( "#textPatientage" ).val(data[0].c_patient_age);
  $( "#textPatientsex" ).val(data[0].c_patient_sex);
  $( "#textPhonenumber" ).val(data[0].c_patient_mob);
  $( "#textemail" ).val(data[0].c_patient_email);
  $( "#textdoctor" ).val(data[0].c_patient_doctor);
  $( "#patient_id" ).val(data[0].c_patient_id);
});
});
</$cript>