0

I am working on a multiple selection using chosen jquery. the values are already stored on an array. But im having problem with the AJAX post to send the values of the array to the controller. I already looked over the internet for solutions, spent so much time on reading articles here but non of it solves my problem. Please help.

Here is my code:

 $(document).ready(function(){ 
    var status = [];
    var method = $(this).attr('data-method');    // confirm(status);
    var config = {
      '.chosen-select'           : {},
      '.chosen-select-deselect'  : {allow_single_deselect:true},
      '.chosen-select-no-single' : {disable_search_threshold:10},
      '.chosen-select-no-results': {no_results_text:'Oops, nothing found!'},
      '.chosen-select-width'     : {width:"95%"}
    }
    for (var selector in config) {
      $(selector).chosen(config[selector]);
    }
        $("#test").chosen().change(function(e, params){

      console.clear()

      $("#test :selected").each(function(i,selected)
      {

             status[i] = $.trim($(selected).text());
            // status.push($(this).val());
      })

    console.log(status);     
    var new_var = JSON.stringify(status);


    // $('.statusArray').click(function(e){

      $.ajax({
        type: "POST",
        url: "<?php echo site_url('request/buyer') ?>",
        data: { data: new_var }
      }).done(function(data) {
        console.log(data);
        alert( "Data Send:");
      }).fail(function() {
        alert( "Data Not Send" );
      });
      e.preventDefault();



    enter code here
    // });


     });    });
10
  • is there any error on developer console ? Commented Jan 11, 2017 at 8:18
  • no there isnt any error on the console. the console only displays the array and its value.. Commented Jan 11, 2017 at 8:20
  • I think data parameter is incorrect. Please try without data : new_var instead data: { data: new_var } refer -- stackoverflow.com/questions/10078085/… Commented Jan 11, 2017 at 8:23
  • i did the same thing on the link that you provided.. im still not getting the value of the array passed to my controller. Commented Jan 11, 2017 at 8:40
  • Check for correctly request to php file from Developers Tools -> tab Network Commented Jan 11, 2017 at 9:06

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.