簡體   English   中英

Codeigniter中jquery.ajax的內部服務器錯誤

[英]Internal server error for jquery.ajax in codeigniter

這是我的ajax代碼

$.ajax({
                method: 'post',
                url: "<?php echo base_url(); ?>"+"ci_ajax/test",
                data: {run : "1"},
                success: function(data) {
                    $("#index_all").html(data);

                },
                error: function(e) {
                    console.log('Error' + e);
                },
            });

這是我在控制器中的服務器端方法代碼

public function test(){
    $post = $this->input->post("run");

    echo $post;
}

但是在控制台日志中,我收到此錯誤

POST http:// localhost / ci_ajax / test 500(內部服務器錯誤)

和console.log錯誤功能的結果是

錯誤[對象對象]

有解決的主意嗎?

更改method以從ajax代碼type

你的ajax應該是這樣的:

$.ajax({
      type: 'post',
      url: "<?php echo base_url('ci_ajax/test'); ?>",
      data: {run : "1"},
      success: function(data) {
         console.log(data);
         $("#index_all").html(data);

      },
      error: function(e) {
         console.log('Error' + e);
      },
});

您的test方法應如下所示:

public function test()
{
    $post = $this->input->post("run");

    echo $post;
    exit;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM