0

I have array with more than 10 records in it and i want to pass it to the controller but it pop ups the error saying bad request.

Following is my code:

$('#submit_fourth').click(function(){
        //send information to server
             $.ajax({
            type: 'POST',
            url: '<?php print site_url('orgnization/storeData'); ?>/'+fields


        });

    });

As shown in the code, fields is the array containing data. Now following is the error message in the firebug.

enter image description here

Any help ?

4 Answers 4

1

try this:

$('#submit_fourth').click(function(){
        //send information to server
             $.ajax({
            type: 'POST',
            data: {fields:fields},
            url: '<?php print site_url('orgnization/storeData'); ?>/'
           success: function(data)
            {
                  console.log('Success');
            }

            });

        });

and in php code:

    public function storeData()
    { 
      ....
      if($this->input->post())
      {
                $fields = $this->input->post('fields'); 
      }
      ....
    }
Sign up to request clarification or add additional context in comments.

Comments

1

You are sending data array in wrong format.See example below

$.ajax({
  type: "POST",
  url: "<?php print site_url('orgnization/storeData'); ?>",
  data: { name: "John", location: "Boston" }//your data will send in this format
})

Comments

1

Use JSON.stringify() before you post data; and give it in data, dont append in url.

$('#submit_fourth').click(function(){
    //send information to server
         $.ajax({
        type: 'POST',
        url: '<?php print site_url('orgnization/storeData'); ?>/',
        data: JSON.stringify(fields)


    });

});

Comments

0

Try this, if you want to send GET request:

$data = array('foo'=>'bar',
              'baz'=>'boom',
              'cow'=>'milk',
              'php'=>'hypertext processor');


echo site_url('orgnization/storeData') . '?' . http_build_query($data);

and type: 'POST' change to type: 'GET'

If you want send POST:

$.post("<?php print site_url('orgnization/storeData'); ?>", <?php echo json_encode($data); ?>)
   .done(function( data ) {
      alert( "Data Loaded: " + data );
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.