1

'JavaScript連想配列名'オプション'

<script>
options[dynamickey] = Number; 
</script>

jQuerypostを使用してこの配列をcodeigniterモデルに送信したいだけです

<script>
$.('link',options);
</script>

しかし、問題は、この配列(オプション)の各キーと値を抽出する方法がわからないことです。データを含む私のJavaScript配列は次のようになります

 <script>
  options { 
     id => 135,
     'Chestnut' => 11,
     'Cinamon' => 1
   }
</script>

codeigniter(PHP)モデルでは、この配列を次のように抽出したいだけです

<?php
 $id = $this->input->post('id');
//below variable names and data should be dynamic from that javascript array
$chesnut= $this->input->post('dynamic value');
?>

これを解決するのを手伝ってください。

4

2 に答える 2

2

あなたのjQueryで、投稿を行います:

var options = { 
    'id' : 135,
    'Chestnut' : 11,
    'Cinamon' : 1
}

$.post('example.com/index.php/firstsegment/secondsegment',options,function(data){...});

この投稿を受け取る CodeIgniter コントローラでは:

public firstsegment extends CI_Controller {

    public function secondsegment(){
        $data = $this->input->post();

        if($data){
            /*
            $data will contain this:
            $data = array(
                'id' => '135',
                'Chestnit' => '11',
                'Cinamon' => '1'
            );
            */
        }
    }
}
于 2012-05-14T12:59:26.617 に答える
0

率直に言うと、まれな要求です。おそらくシステムによってレンダリングされたものをシステムに送信したいですか?

それにもかかわらず。jQuery ajax{ data : options }の既存の共通値とともにa を追加します。

例:

var options = { 
    'id' : 135,
    'Chestnut' : 11,
    'Cinamon' : 1
}

$.ajax({
  type: "POST",
  url: "some.php",
  data: options
}).done(function( msg ) {
  alert( "Data Saved: " + msg );
});
于 2012-05-14T12:55:02.857 に答える