Welcome Guest, Not a member yet? Register   Sign In
Not return json value on ajax call
#1

[eluser]Unknown[/eluser]
view:
$("#ref_for").change(function(){
var depart = $('#ref_for').val();
$.ajax({
url: "patient/getPhysician",
data: +depart,
type: "post",
success: function(data){
alert(data);
$.each(data,function(uid,fname)
{
var opt = $('<option />');

opt.val(uid);
opt.text(fname);
$('#ref_to').append(opt);
});
},error:function(){
alert('ajax failure');
}
});
});


controller:
public function getPhysician()
{
$ref_for = $this->input->post('ref_for');
$this->load->model('patientmodel');
$data['get_physician'] = $this->patientmodel->getPhysician($ref_for);
echo json_encode($data);
print $results;
}

model:
function getPhysician($ref_for) {
$query = $this->db->query('select u_id,fname,lname from users where dd_id=?', array($ref_for));
if ($query->num_rows() > 0) {
foreach ($query->result() as $arow) {
$data['u_id'] = $arow->u_id;
$data['fname'] = $arow->fname;
}
return $data;
}
#2

[eluser]Ckirk[/eluser]
When developing websites I use Firefox and disable caching to ensure that any changes you make to your javascript, css, images etc is seen immediately in the browser when you refresh.

to disable caching in firefox: type "about:config" in the address bar and set the following 2 values:
Code:
network.http.use-cache = false
browser.cache.offline.enable = false

Make sure you have the firebug plugin running and refresh your page. Watch the "Console" and it should tell you why you're not getting json back when you click your option.


Additionally enter the url manually and you should see json on your screen. You may find that your ajax call is not finding the url.
eg. If your url is http://yourdomain.com/patient/getPhysician then try adding a "/" to the front of your ajax URL call:

Code:
$.ajax({
      url: “/patient/getPhysician”,
      ...................

Hope that's enough to get you to the bottom of your problem




Theme © iAndrew 2016 - Forum software by © MyBB