質問

I have finally got magicsuggest working with json on codeigniter. The only issue that i have now is that when i post the values are like ["1"], is there any way (other than preg_replace() or str_replace) that i can strip everything so that i have just the number or string without the quotes and square brackets.

Below is the controller function

public function json_hotelquery() {
    $query = $this -> tourquery -> get_hotels();

    $return_arr = array();
    foreach ($query->result() as $row) {
        $row_array['id'] = $row->id;
        $row_array['name'] = $row->hotelname;

        array_push($return_arr,$row_array);
    }
    $this->output->set_content_type('application/json');
    $this->output->set_output(json_encode($return_arr));

}

and this is the jquery for magicsuggest

$('#hotel_name').magicSuggest({
    selectionPosition: 'bottom',
    selectionStacked: true,
    maxSelection : 1,
    displayField: 'name',
    data: '<?php echo site_url('dashboard/json_hotelquery'); ?>'
});

And this is the output from post

Array([hotel_name] => ["5"])
役に立ちましたか?

解決

Sorry for the delay maldivianGeek. I'm the author of the plugin and have been overbooked the past couple of months :( Anyways with the latest 2.0 release the passed values will just be like if you were passing a bunch of checkbox values. You can check out the new documentation and tutorial page that explains that pretty well.

Cheers

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top