Strange jquery behavior

I use the codeigniter framework and I use jquery. Now I have one checkbox that contains the values ​​from the database. I checked its values ​​using the jquery change event and warning field. This gives the exact value in the warning box when changing, but when I use the post method or get or even $ .ajax (), it does not give any output. Actually I checked with console.log (), and that is not included in this. I just need to post some values ​​and get some information from the database to show in the div just below this select box. Here is 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
});
+3
source share
3 answers

...

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:

console.log(org_name); . org_name, ?

+1

.ajax jQuery (error variable) . - , XMLHttpRequest, textStatus, errorThrown variables

+1

thanks for the answer guys, this callback method helped me a lot. It gave a 404 method, so I changed the URL. Now it works like a charm. Let me share with you all that I have done:

$('#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
    }
  });  
});
0
source

Source: https://habr.com/ru/post/1759508/


All Articles