Reputation: 6346
I'm using Jquery ajax to call a CodeIgniter function:
$.ajax({
type: "POST",
dataType:'json',
beforeSend: function() {
$("#opc").addClass("opacity");
$("#searching").show();
},
url: "<?php echo base_url(); ?>search/get_results",
data: {
'ns_pos':ns_pos,
'NSPlaceDomainID':activity,
'DistrictID':area,
'NSAssociationID':referer,
'Title':text,
'SettlementID':settlement,
'NoOpinion':$("input[name=NoOpinion]").is(":checked"),
'SpecialCharacteristics':ns_attr
}
etc...
In the Chrome console I get the message:
POST http://mattat.org.il/ci/index.php/search/get_results 404 (Not Found)
the response preview is:
Not Found
The requested URL /ci/index.php/search/get_results was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
However, this function does exist, as is evident when I simply paste the link in the URL line.
I'm confused...
edit: Following @paul's constructive comment I have changed the request to GET and, indeed, the page was found. What can cause such an obscure behaviour?
One more step: When I empty the data object (like so: data: {}), the function is found even with POST request
Upvotes: 2
Views: 3754
Reputation: 10780
This same issue had me baffled. It turned out to be an Apache permissions problem. I checked with my hosting provider and they confirmed, fixed it and showed me how to setup a Cron job that runs every hour to reassert proper permissions. They also suggested I use FileZila rather than WinSCP and provided me with the settings to automatically reset permissions on reuploading files.
Upvotes: 0
Reputation: 1
Instead of using base_url()
please use site_url()
. I have experienced the same issue.
A simple example could be given as follows in which an ajax jQuery posting is viewed.
$.post("<?php echo site_url('message/add') ?>", {message: msg}, function() {
$('#content').load("<?php echo site_url('message/view/ajax') ?>");
$('#message').val('');
});
Message/add here as you can guess the function is defined in controller. As I firstly deal with php, I searched for a good example. I am not only news at php but also at codeigniter. In many example, the implemented form is like "base_url+message/add". It might be possible that codeigniter version leads to this error since all of them were written by the version prior to 2.X. Anyway, if you want to have a ready code please check the following link, it worked for me!
jQuery ajax codeigniter example
Upvotes: 0
Reputation: 306
As Paul already pointed, it is likely an error due to GET/POST limitation. Check your server code if you support POST requests on this endpoint.
Upvotes: 2