var dataString = JSON.stringify(formDara);
console.log(dataString);
$.ajax({
url: urL,
type: "POST",
cache: false,
data: dataString,
success: function (data) {
console.log(data);
}
});
这里,formData
是一个对象。
console.log(dataString)OUTPUT:
{"library_fee":"100","lab_fee":"200","tution_fee":"300","admission_fee":"400"}
但是我的控制器没有价值。 Codeigniter控制器ACTION方法:
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();
}
答案 0 :(得分:0)
试试这个@Ikram Hasib
方法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);
}
});
方法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);
});