0
我想問,如何從CodeIgniter RESTful Server上的數組中的序列化數據接收數據?CodeIgniter:如何在RESTful Server上接收序列化數組中的數據?
阿賈克斯
$.ajax({
type: 'POST',
url: "/mywebsite/api/index.php/purchase",
data: $("#formdatatrans").serialize(),
success: function(response) {
alert("Success");
}
});
HTML表單
<input type="text" name="data1[]">
<input type="text" name="data2[]">
<input type="text" name="data3[]">
<input type="text" name="data4[]">
控制器
function index_post() {
$data = array(
'data1' => $this->post('data1'),
'data2' => $this->post('data2'),
'data3' => $this->post('data3'),
'data4' => $this->post('data4'));
$insert = $this->db->insert('table1', $data);
if ($insert) {
$this->response($data, 200);
} else {
$this->response(array('status' => 'fail', 502));
}}
輸入數據
Array [0]
Data1 = abc_1
Data2 = abc_1
Data3 = abc_1
Data4 = abc_1
Array [1]
Data1 = abc_2
Data2 = abc_2
Data3 = abc_2
Data4 = abc_2
如何使用/循環的同時,一次性添加所有的數據之上?
在此先感謝