1

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 Answers 2

1

Try doing this way in your ajax function ,

url : <?php echo base_url(). 'home/ajax' ; ?>, type : POST,

Sign up to request clarification or add additional context in comments.

3 Comments

I think here you might consider <?php echo base_url('home/ajax'); ?> instead
Agreed . It's even better.
use this redirect(base_url('home/login')) in your ajax function
0

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.

8 Comments

I try that already i can load function ajax from my controler its ajax part problem i cant figure it out, ajax wont load function in my controller
I assume English is not your first language so no worries there, but I'm having a hard time understanding your question. Can you browse to http://localhost/home/ajax? If so, what do you see?
Sorry for my bad english, yes its ok localhost/home/ajax when i type in url , but when i click on button ajax request dont work, it should be run localhost/home/ajax but nothing happens
Okay then my initial idea was wrong -- the only thing I can think of now is that the ajax isn't even being fired. You can add an alert before $.ajax to test this, otherwise I'm stumped, sorry!
Do you mind if I ask why you're trying to do a redirect in the controller? Try removing the redirect and echoing out a string and then alert that in the ajax. That's an easy way to test that you're actually sending info to the controller.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.