?Briella 2014-06-25 20:39 采纳率: 0%
浏览 21

使用Ajax的CodeIgniter

I cant find error when i click on a button nothing happens, i dont get any error in console, very is error maybe in data field?

I have ajax part

$(document).ready(function() {
    $('#brisanje').click(function() {
        $.ajax({
            url: 'localhost/test2/home/ajax',
            type: 'Post',
            data: form_data,
            success: function() {
                alert("paun");
            }
        });
    });
});

button

<button type="submit"  id="brisanje" class="btn btn-danger btn-xs">Obriši sliku</button>

and controler

 public function ajax(){
     redirect('home/login');
 }
  • 写回答

2条回答 默认 最新

  • weixin_33720186 2014-06-25 20:45
    关注

    Answer: Redirecting in the ajax() function caused the problem. I'll leave my junk here anyway, but since I got the checkmark I best provide the actual answer!


    This doesn't seem to solve the problem, but I'll leave it here for now anyway


    It looks like you're missing the "Action" part of your controller action. You probably are getting a 404 error, although I can't remember exactly what happens when CI cannot find the controller action. Maybe its a 403 error.

    Anyway, try naming your ajax function ajaxAction and see if that works. A way to test this would be to browse directly to the url http://localhost/home/ajax (bypass the actual ajax) and you should see any errors that occur.

    If you're using a browser with a debugger (most of them, push F12 and see what you get), you should also be able to see the ajax request firing in the console or network tab, and then you can inspect the response for errors.

    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧