Laravel ajax url not working on production server

laravel ajax form submit not working
ajax post not working but get works
ajax url in laravel
laravel ajax url route with parameters
laravel ajax controller
ajax is not a function laravel
laravel api post request not working
post data using ajax in laravel

I have this ajax request on my Laravel Project (this is a simple version but it is working):

$.ajax({
            method: 'POST', // Type of response and matches what we said in the route
            url: '/admin/lessons/addMember/licenseMemberId', // This is the url we gave in the route
            data: {'licenseMemberId' : id},
            success: function(response){ 
                console.log(response);

                if ($.trim(response)) {
                    var actualMembers = document.getElementById("actual-member");
                }
                $('#membersModal').modal('hide');
            },  
        });

When I work locally and I use php artisan serve the ajax call works, but when i deploy to my production server doesn't (because the path /admin/lessons/addMember/licenseMemberId is not the full path in the server). The best way shoud be using the route, but I don't know how. This is the routing table:

web                                          |
|        | POST      | admin/lessons/addMember/{licenseMemberId}                     | lessons.addMember               | App\Http\Controllers\admin\LessonController@addMember  

Is there a way to use the laravel route with the paramether? If not, how can I do?

You shouldn't use URLs in Laravel the way you use it in vanila php or html, use the URL function, this function ensures that your route is pointing currectly to the project root, in your case you can do something like this

$.ajax({
        method: 'GET', 
        url: '{{URL::to('/admin/lessons/addMember/')}}' + id, 
// Laravel will print the url and you just need to concat your id to it
        success: function(response){ 
            console.log(response);

            if ($.trim(response)) {
                var actualMembers = document.getElementById("actual-member");
            }
            $('#membersModal').modal('hide');
        },  
    });

Notice that im using GET as you seem to be retrieving data and not POSTING it, however if you need to post it, the MisaGH answer is the way to go

Laravel ajax url not working on production server, I have this ajax request on my Laravel Project (this is a simple version but it is working): $.ajax({ method: 'POST', // Type of response and matches what we said​  Search less. Build more. Use Stack Overflow for Teams at work to share knowledge with your colleagues. Free 30 day trial. Start your trial.

Do not receive the parameter in route.

URL should be : /admin/lessons/addMember

$.ajax({
            method: 'POST', // Type of response and matches what we said in the route
            url: '/admin/lessons/addMember', // This is the url we gave in the route
            data: {'licenseMemberId' : id},
            success: function(response){ 
                console.log(response);

                if ($.trim(response)) {
                    var actualMembers = document.getElementById("actual-member");
                }
                $('#membersModal').modal('hide');
            },  
        });

And the controller:

$member_id = request('licenseMemberId');

Laravel and AJax on localhost working, but online Ajax request not , All Ajax requests not working in the whole website. problem at online which is the URL() or the Ajax request not working anytime. and for sure, the DataTable works well on local, no no problem in the server side, and now  jqgrid paging on server side. jquery,jqgrid,server,paging. You are doing asynchronous calls in find but in your callback you have other statement after find. These will be executed before find finishes.

The real route is

admin/lessons/addMember/{licenseMemberId}   

so in javascript you need to call

'/admin/lessons/addMember/' + id 

where id is a variable. In the controller you can use the id getting

Input::get('licenseMemberId') or $request->get('licenseMemberId'); 

Laravel 5 can't use ajax post request, Hello, I am using laravel 5 for my project. Are you sure you generate the good url with : But as @bashy says, any problems with Ajax, you should be using tools to check that you're actually getting a response to the post. Forum Laravel The requested URL /login was not The requested URL /login was not found on this server. The most concise screencasts for the working developer

Ajax working on localhost but not on server - JavaScript, Ajax working on localhost but not on server function getCities(countryid){ jQuery('#loadingimage').show(); jQuery.ajax({ type: "POST", url:  Ajax (Asynchronous JavaScript and XML) is a set of web development techniques utilizing many web technologies used on the client-side to create asynchronous Web applications. Import jquery library in your view file to use ajax functions of jquery which will be used to send and receive data using ajax from the server.

ajax post in laravel 5 return error 500 (Internal Server Error), Forum > ajax post in laravel 5 return error 500 (Internal Server Error) whats wrong/problem to my code? anything im missing? any help, ideas, clues, $.​ajax({ url: "test", type:"POST", data: data, success:function(data){ alert(data); }  Laravel Vapor is a serverless deployment platform for Laravel, powered by AWS. Launch your Laravel infrastructure on Vapor and fall in love with the scalable simplicity of serverless. Laravel Vapor is fine-tuned by Laravel's creators to work seamlessly with the framework so you can keep writing your Laravel applications exactly like you're used to.

Laravel Ajax 500 Internal Server error - 5+ Reasons, var request = $.ajax({ url: "script.php", method: "POST", data: { _token : <?php Other reasons that can give you Laravel 500 Internal Server Error problem might​  Laravel allows you to easily create "signed" URLs to named routes. These URLs have a "signature" hash appended to the query string which allows Laravel to verify that the URL has not been modified since it was created. Signed URLs are especially useful for routes that are publicly accessible yet need a layer of protection against URL manipulation.

Comments
  • In post method you can send the {licenseMemberId} with ajax data parameter, not route parameter.
  • Can you post your controller method?
  • Thank you but when I put your code in production server still don work, I dot this console error: bosco.com/admin/lessons/addMember/licenseMemberId -->not found, the problem is that my project is in a subdirectory it should be bosco.com/sg3000/public//admin/lessons/addMember/…
  • If /sg3000/public is really part of your public url, you need to go there... bit strange though
  • so the best practice is not to pass the parameters with route parameter when I have a POST method? Or it is good only when I use it in an ajax script? Because I use this route also in others parts of my code, but normal php code...
  • You can do whatever you want. But I think this approach for ajax calls is much better.