Reputation: 57
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');
}
Upvotes: 1
Views: 58
Reputation: 2626
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.
Upvotes: 0
Reputation: 636
Try doing this way in your ajax
function ,
url : <?php echo base_url(). 'home/ajax' ; ?>,
type : POST,
Upvotes: 1