PHP: laravel: ajax get request fails

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

publicGenome
Forum Contributor
Posts: 110
Joined: Thu Apr 16, 2015 7:55 am

PHP: laravel: ajax get request fails

Post 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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP: laravel: ajax get request fails

Post 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?
publicGenome
Forum Contributor
Posts: 110
Joined: Thu Apr 16, 2015 7:55 am

Re: PHP: laravel: ajax get request fails

Post 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 ..
publicGenome
Forum Contributor
Posts: 110
Joined: Thu Apr 16, 2015 7:55 am

Re: PHP: laravel: ajax get request fails

Post by publicGenome »

Do you think it could be different version of Apache?
Same thing works on my different machine, but having different apache version.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP: laravel: ajax get request fails

Post 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.
publicGenome
Forum Contributor
Posts: 110
Joined: Thu Apr 16, 2015 7:55 am

Re: PHP: laravel: ajax get request fails

Post 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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP: laravel: ajax get request fails

Post by Celauran »

publicGenome wrote:How do I request URI?
Type it in your browser's address bar?
publicGenome
Forum Contributor
Posts: 110
Joined: Thu Apr 16, 2015 7:55 am

Re: PHP: laravel: ajax get request fails

Post 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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP: laravel: ajax get request fails

Post by Celauran »

publicGenome wrote:Nope, that doesn't work.
You need to be a lot more specific than that.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP: laravel: ajax get request fails

Post 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?
publicGenome
Forum Contributor
Posts: 110
Joined: Thu Apr 16, 2015 7:55 am

Re: PHP: laravel: ajax get request fails

Post 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.
Attachments
Screen Shot 2016-04-21 at 10.12.27 AM.png
publicGenome
Forum Contributor
Posts: 110
Joined: Thu Apr 16, 2015 7:55 am

Re: PHP: laravel: ajax get request fails

Post 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
publicGenome
Forum Contributor
Posts: 110
Joined: Thu Apr 16, 2015 7:55 am

Re: PHP: laravel: ajax get request fails

Post by publicGenome »

I've this feeling it is due to some server settings.. But can't find seem to find needle in the haystack. :(
publicGenome
Forum Contributor
Posts: 110
Joined: Thu Apr 16, 2015 7:55 am

Re: PHP: laravel: ajax get request fails

Post 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
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP: laravel: ajax get request fails

Post 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.
Post Reply