当我在 codeigniter 3.1.7 中调用 ajax 时,它可以自动获取 ajax url 中的基本 url
AJAX 调用代码:
$(document).on("click",".btn_edit",function(){
var id = $(this).attr("id");
$("#btnsave").attr("mode","update");
$("#myModal").modal("show");
console.log(id);
$.ajax({
type :"post",
url :"Home/get_emp",
data :{"id":id},
dataType : "json",
success : function(edit_feed){
$("#txtempid").val(edit_feed.e_id);
$("#txtempname").val(edit_feed.e_name);
$("#selempskill option:contains('"+edit_feed.e_skill+"')").prop('selected',true);
$("#prev_img").attr("src",base_url+edit_feed.e_img);
var lbl = edit_feed.e_img.split("/");
$("#pic_label").html(lbl[3]);
}
});
});
Controller :
class Home extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->model('Emp_model');
}
public function index(){
//$this->load->view('index');
$this->load->view('home');
}
public function get_emp(){
$id=$_POST['id'];
$data = $this->Emp_model->get_emp($id);
echo json_encode($data);
}
错误:
jquery.3.2.1.js:3049 POST http://localhost/cod_std/Home/get_emp 404 (Not Found)
这里我只想调用 Controllers Home 及其函数 get_emp 请给我一些我使用 codeigniter3.1.7 的解决方案
最佳答案
你可以试试:
url:"<?php echo site_url("Home" . '/get_emp'); ?>",
关于php - codeigniter 中的 Ajax 调用不像我预期的那样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48959945/