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
    // });


     });    });
Yigit Yuksel
  • 1,060
  • 2
  • 18
  • 35
Karl
  • 3
  • 9
  • is there any error on developer console ? – Yigit Yuksel Jan 11 '17 at 08:18
  • no there isnt any error on the console. the console only displays the array and its value.. – Karl Jan 11 '17 at 08:20
  • I think data parameter is incorrect. Please try without `data : new_var` instead `data: { data: new_var }` refer -- http://stackoverflow.com/questions/10078085/how-to-send-multiple-data-with-ajax-jquery – softbrewery Jan 11 '17 at 08: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. – Karl Jan 11 '17 at 08:40
  • Check for correctly request to php file from Developers Tools -> tab Network – softbrewery Jan 11 '17 at 09:06
  • I got 2 404 errors on the network tab when i checked. How do i fix it? it says the cause is xhr – Karl Jan 11 '17 at 09:34
  • After load page clear all request in Network tab and then make ajax request. Must be view only your request. – softbrewery Jan 11 '17 at 09:53
  • @htmlbrewery - Yes i was able to see the ajax request on the network tab and i can see the value of the array in the parameters when i click on one request but the response is "NULL" what seems to be the problem in my ajax request? – Karl Jan 11 '17 at 23:05
  • if response is `NULL` possible problem come from server not ajax. Please see form parameters which you sent to server. – softbrewery Jan 12 '17 at 07:20
  • been working on this since last week.. i do not know where to start debugging.. the values are showing on the params in the network tab on my debugger but NULL value are showing when i submit the page. – Karl Jan 16 '17 at 04:07

0 Answers0