Füllen Sie die Optionen des zweiten Auswahlfelds basierend auf der Auswahl im ersten Auswahlfeld mithilfe von AJAX in eiPhp

PHP-Programmierer chatten hier
Anonymous
 Füllen Sie die Optionen des zweiten Auswahlfelds basierend auf der Auswahl im ersten Auswahlfeld mithilfe von AJAX in ei

Post by Anonymous »

Ich möchte die ID mithilfe von Ajax aus dem Index übernehmen, um sie an den Controller weiterzuleiten. Der Controller gibt die Kategorie-ID mithilfe von JSON aus und liefert sie an die Indexdatei.
Controller

Code: Select all

public function index()
{
$this->load->model('sales/Sales_model');
$this->load->model('product/Product_model');

$user_info['p_info'] = $this->Product_model->fetch_data();
$this->load->view('sales/index', $user_info);
}

public function get_pcatagory()
{
$this->load->model('sales/Sales_model');
$pid = $this->input->post('pro_id');

$cat_info = $this->Sales_model->fetch_data_pid($pid);

if (count($cat_info) > 0) {
$select_box = '';
$select_box .= 'Select Catagory ID';
foreach ($cat_info as $value) {
// $value->id data will go to option of the select menu
}
echo json_encode($select_box);
}
}
Modell

Code: Select all

public function fetch_data_pid($pid)
{
$query = $this->db->get_where('product', array('id' => $pid));
return $query->result();
}
Ajax

Code: Select all

$(document).ready(function(){
$('#pid').on('change',function(){
var pro_id_data = $('#pid').val();
alert(pro_id_data);
$.ajax({
url: 'sales/get_pcatagory',
type: 'POST',
data: {'pro_id' : pro_id_data},
dataType: 'json',
success:
function(result){
$('#cate').html(result);
},
error:
function(){
alert('error')
}
});
});
});

Ansicht

Code: Select all

Product ID

Select Product ID

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post