Page 1 of 2

PHP: laravel: ajax get request fails

Posted: Wed Apr 20, 2016 5:57 pm
by publicGenome
Hi There,
I've an application working on my local, and am in a phase of transitioning the same code to another server.

Code works on old version, however at new location PHP code fails. It is AJAX Get request is failing.
I get error:

[text]
The requested URL /pims/public/illumina/illumina_xhr_get_samples was not found on this server.
[/text]

My local host points to ~/Sites

New apache version:
Server version: Apache/2.4.18 (Unix)

Old Apache version:
Server version: Apache/2.2.29 (Unix)

Old Php version:
PHP 5.5.24 (cli) (built: Apr 17 2015 18:54:39)

New Php version:
PHP 5.5.34 (cli)

New here means new physical location
Old means my machine

Ajax request looks like:

Code: Select all

	$.ajax({
		mtype:"GET",
		url:"illumina/illumina_xhr_get_samples",
		data:{stdy:'study_name'},
		datatype: "json",
		success:function(data){
			alert("wow");
			},
			error:function(){
				console.log("the value");
				alert("error");
				}
		});
I've route in laravel as:

Code: Select all


Route::group(['prefix' => 'illumina', 'namespace' => 'TGen\\Controllers\\illumina','before' => 'pims_auth'], function() {
	if(Request::ajax()){
		// xhr in all requests so to distinguish AJAX  from any other 
		
		Route::get('illumina_xhr_get_samples','mainIllumina@get_illumina_samples');
}
});
How do I fix this?
Please help.

Re: PHP: laravel: ajax get request fails

Posted: Wed Apr 20, 2016 8:00 pm
by Celauran
You have mtype: instead of type:, so it could be something as simple as that. Does it work if you hit the route directly in browser?

Re: PHP: laravel: ajax get request fails

Posted: Thu Apr 21, 2016 7:00 am
by publicGenome
Celauran wrote:You have mtype: instead of type:, so it could be something as simple as that. Does it work if you hit the route directly in browser?
Hi Celauran,
Thanks for your reply.

- It doesn't take me to the desired page if I type it in browser.
- type instead of mtype, doesn't work ..

Re: PHP: laravel: ajax get request fails

Posted: Thu Apr 21, 2016 7:08 am
by publicGenome
Do you think it could be different version of Apache?
Same thing works on my different machine, but having different apache version.

Re: PHP: laravel: ajax get request fails

Posted: Thu Apr 21, 2016 8:12 am
by Celauran
Well, it clearly isn't an AJAX problem if it's not working in the browser either. If it's working on one machine and not on another, that certainly does suggest server configuration issues. You haven't really explained how it isn't working, though. What happens when you request that URI? There were definitely some changes between Apache 2.2 and 2.4. There's also the fact that OS X rewrites config files when upgrading Apache. If we know what the error scenario looks like, we can maybe suggest what to try to remedy it.

Re: PHP: laravel: ajax get request fails

Posted: Thu Apr 21, 2016 8:16 am
by publicGenome
Hi Celauran,
How do I request URI? Sorry, don't know ..

I've .htaccess file as:
[text]
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

[/text]

This is AS IS on both machines.

Re: PHP: laravel: ajax get request fails

Posted: Thu Apr 21, 2016 8:19 am
by Celauran
publicGenome wrote:How do I request URI?
Type it in your browser's address bar?

Re: PHP: laravel: ajax get request fails

Posted: Thu Apr 21, 2016 9:04 am
by publicGenome
Hi,
Nope, that doesn't work.

Cannot understand why I've an extra / in URL:

Code: Select all

The requested URL /pims/public/illumina/illumina_xhr_get_samples was not found on this server.

Re: PHP: laravel: ajax get request fails

Posted: Thu Apr 21, 2016 9:07 am
by Celauran
publicGenome wrote:Nope, that doesn't work.
You need to be a lot more specific than that.

Re: PHP: laravel: ajax get request fails

Posted: Thu Apr 21, 2016 9:09 am
by Celauran
publicGenome wrote:I've route in laravel as:

Code: Select all


Route::group(['prefix' => 'illumina', 'namespace' => 'TGen\\Controllers\\illumina','before' => 'pims_auth'], function() {
	if(Request::ajax()){
		// xhr in all requests so to distinguish AJAX  from any other 
		
		Route::get('illumina_xhr_get_samples','mainIllumina@get_illumina_samples');
}
});
publicGenome wrote:

Code: Select all

The requested URL /pims/public/illumina/illumina_xhr_get_samples was not found on this server.
Those routes don't match. What's the extra /pims/public about?

Re: PHP: laravel: ajax get request fails

Posted: Thu Apr 21, 2016 9:14 am
by publicGenome
Celauran wrote:
publicGenome wrote:Nope, that doesn't work.
You need to be a lot more specific than that.
Hi,

Please find attached screen shot for the error I get.

Re: PHP: laravel: ajax get request fails

Posted: Thu Apr 21, 2016 9:15 am
by publicGenome
Celauran wrote:
publicGenome wrote:I've route in laravel as:

Code: Select all


Route::group(['prefix' => 'illumina', 'namespace' => 'TGen\\Controllers\\illumina','before' => 'pims_auth'], function() {
	if(Request::ajax()){
		// xhr in all requests so to distinguish AJAX  from any other 
		
		Route::get('illumina_xhr_get_samples','mainIllumina@get_illumina_samples');
}
});
publicGenome wrote:

Code: Select all

The requested URL /pims/public/illumina/illumina_xhr_get_samples was not found on this server.
Those routes don't match. What's the extra /pims/public about?
It is there
pims is the laravel main folder..
~/Sites -->pims-->public

Re: PHP: laravel: ajax get request fails

Posted: Thu Apr 21, 2016 9:29 am
by publicGenome
I've this feeling it is due to some server settings.. But can't find seem to find needle in the haystack. :(

Re: PHP: laravel: ajax get request fails

Posted: Thu Apr 21, 2016 10:00 am
by publicGenome
Fixed it:
I had to enable

Code: Select all

 LoadModule rewrite_module libexec/apache2/mod_rewrite.so

I was unable to run other my pet applications, and upon that I got error:

[text]
Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at you@example.com to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.
[/text]
I used help from :
http://stackoverflow.com/questions/1014 ... ned-by-a-m

I checked:
/var/log/apache2/error_log
Found error:
[text]
learn_routing/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
[/text]

Then, fixed:
[text]
/etc/apache2/httpd.conf
[/text]
I hope someone gains from this. :)
Cheers,
pG

Re: PHP: laravel: ajax get request fails

Posted: Thu Apr 21, 2016 10:08 am
by Celauran
publicGenome wrote:I checked:
/var/log/apache2/error_log
Found error:
[text]
learn_routing/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
[/text]
Awesome.

Pro tip: use virtual hosts for your projects and have separate log directories / files for each project. /var/log/httpd/project-name/error.log means not having to sift through errors from unrelated code.