views:

62

answers:

3

Hi friends,

I am using codeigniter framework and in view i am using jquery. Now, I have one select box which contains values from database. I tested the values of it using jquery change event and alert box. Its giving exact value in alert box on change, but when i am using post method or get or even $.ajax(), its not giving any output. In fact i checked with console.log(), its not going inside that too. I just need to post some values and get some info from database to show in the div just below that select box. Here's the code for jquery:

$(document).ready(function(){
   $('#org_name').change(function(){
       $.post('index.php/contact/getorg',{'query':$('#org_name').val()},function(data){
         console.log("inside post"); 
         $('#showorg').html(data);
         console.log(org_name);
       });//close post function
   }); //close org_name event function
});

I appreciate your help in this. thanks

+1  A: 

Try to use .ajax jQuery method with specified failure function (error variable) in method parameters. If something going wrong on server side or you have another specific error, you'll be able to analyze XMLHttpRequest, textStatus, errorThrown variables

Pavel Morshenyuk
A: 

I am always using the following style...

ajax({
   type: "POST",
   url: 'index.php/contact/getorg',
   data: JSON.stringify({'query':$('#org_name').val()}),
   dataType: "json",
   contentType: "application/json; charset=utf-8",
   success: function (data) {
      $('#showorg').html(JSON.parse(data.d));
   },
   error: showError
};

function showError(responseText, statusText, xhr, $form) {
            debugger;         }

EDIT:

And also the line console.log(org_name); seems not correct. Where is the member org_name comming from?

Yves M.
No clue if this is the problem. Maybe your url: is relative? Try '/index.php/contact/getorg'. Also, use firebug with firefox to diagnose xhr (ajax requests). Then you can see what's really happening.
Matthew
A: 

thanks for the response guys, that error call back method helped me a lot. It was giving 404 method, so i changed the url. Now its working like charm. Let me share with you all what i did:

$('#org_name').bind('change',function(){ $("#showorg").html("wait..."); $.ajax({ url: 'http://localhost/ifes/index.php/contact/getorg', type: 'POST', dataType: 'html', data:{'query':$('#org_name').val()}, timeout: 1000, error: function(xhr,err){ alert("readyState: "+xhr.readyState+"\nstatus: "+xhr.status); alert("responseText: "+xhr.responseText); }, success: function(data){ $('#showorg').html(data);// do something with data } });

}); //close org_name event function

Sorry, i dont how to use the code quotes here...

mad_programmer