0
var dataString = JSON.stringify(formDara);
    console.log(dataString);
$.ajax({
    url: urL,
    type: "POST",
    cache: false,
    data: dataString,
    success: function (data) {
        console.log(data);
    }
});

Here, formData is an Object. console.log(dataString) OUTPUT:

{"library_fee":"100","lab_fee":"200","tution_fee":"300","admission_fee":"400"}

But my controller got no value. Codeigniter controller ACTION method:

public function set_fees_structure($id) {
    $data = array();
    $data["admission_fee"] = $this->input->post("admission_fee", TRUE);
    $data["tution_fee"] = $this->input->post("tution_fee", TRUE);
    $data["library_fee"] = $this->input->post("library_fee", TRUE);
    $data["lab_fee"] = $this->input->post("lab_fee", TRUE);
    echo 'I m set fees structures ' . $id;
    echo '<pre>';
    print_r($data);
    exit();
}
3
  • Add your action method also. You need add to ajax method contentType: 'application/json; charset=utf-8' Commented Jan 16, 2017 at 13:47
  • I already tried. but not working. Commented Jan 16, 2017 at 13:55
  • Possible duplicate of: stackoverflow.com/questions/21004315/… Commented Jan 16, 2017 at 14:03

1 Answer 1

0

Try this @Ikram Hasib

Method 1

    var jsonFile = {
      "coord": {
        "lon": -88.64,
        "lat": 35.44
      },
      "weather": [{
        "id": 701,
        "main": "Mist",
        "description": "mist",
        "icon": "50n"
      }]
    }
    $.ajax({
      type: "POST",
      url: url,
      data: JSON.stringify({
        jsonFile
      }),
      dataType: "json",
      contentType: "application/json",
      Accept: 'application/json; charset=utf-8',
      success: function(data) {
        console.log(data);
      }
    });

Method 2

 var jsonFile = {
   "coord": {
     "lon": -88.64,
     "lat": 35.44
   },
   "weather": [{
     "id": 701,
     "main": "Mist",
     "description": "mist",
     "icon": "50n"
   }]
 }

 $.post(url, JSON.stringify({
     jsonFile
   }))
   .done(function(data) {
     console.log(data);
   });

Sign up to request clarification or add additional context in comments.

3 Comments

When i use dataType: "json", then not work ajax. when use that still not working. for your information, formDara is an Object
@IkramHasib I have added another way too of doing it and updated my old code.
please check that data {"library_fee":"100","lab_fee":"200","tution_fee":"300","admission_fee":"400"}

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.