【问题标题】:ajax or database not workingajax 或数据库不工作
【发布时间】:2018-04-14 19:13:55
【问题描述】:

我已经挣扎了好几天了。我正在通过分配一个输入字段来进行 ajax 回调,但我也无法这样做。下面是代码:

脚本

$('[name="acccode[]"]').each(function(idx,val){
var acccode = $('[name="acccode[]"]').eq(idx).val();
console.log(acccode);
$.ajax({
  url : "<?php echo base_url(); ?>readacccode",
  type: "POST",
  data:"Acc_Code="+acccode,
  dataType: "JSON",
  success: function(data)
  {
    $.each(data.results,function(idx,val){
    console.log(val);
    $('[name="accname[]"]').val(val);
  });
  },
  error: function (data)
  {
      swal("Oops", "We couldn't connect to the server!", "error");
  }
 });
 });

我成功地获得了每个 acc 代码。但不是名字。

这是控制器代码:

  public function readacccode()
  {
    if (!$this->ion_auth->logged_in() || $this->ion_auth->is_store())
    {
         redirect('account/login');
    }
        $acccode = $this->input->post('acccode');
        $data['results']=$this->Setting->get_acccode($acccode);
        echo json_encode($data);
}

它正在获取 acc 代码匹配的 acc 名称。

请指教。

【问题讨论】:

  • 您在数据中发送Acc_Code,您希望从哪里获得pol1
  • edit您的问题,不要在cmets中发布代码。
  • acccode 不是Acc_code,你知道吗?
  • 应该是。然后我可以得到一个匹配。不知道我做错了什么。
  • 你明白acccodeAcc_code不同的键吗?

标签: php jquery ajax codeigniter


【解决方案1】:

谢谢大家,问题已解决。对于那些想知道的人来说,这是我改变的事情。

public function readacccode()
{
if (!$this->ion_auth->logged_in() || $this->ion_auth->is_store())
{
     redirect('account/login');
}
    $acccode = $this->input->post('Acc_Code'); //All I did is replace acccode to Acc_Code
    $data['results']=$this->Setting->get_acccode($acccode);
    echo json_encode($data);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    • 2017-07-20
    • 2023-03-04
    • 1970-01-01
    • 2012-02-06
    相关资源
    最近更新 更多