?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.

    评论

报告相同问题?