Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

wontonesaju's avatar

Issue with ajax post when changing the query string

Hi,

I am facing one issue like in my application i am using query string pattern like for instance user section where i am doing edit user

URL is domain.com/edituser?uid=21

Route::get('edituser','UserController@getuser')->middleware('validuser'); Route::post('processuseredits','UserController@doUpdate')->middleware('ajax','validuser');

This works perfect with ajax also.

But when i am changing this with

URL is domain.com/edituser/21

Route::get('edituser/{uid}','UserController@getuser')->middleware('validuser'); Route::post('processuseredits','UserController@doUpdate')->middleware('ajax','validuser');

it displays the edit user data but when i am submitting the form it giving me post method not supported use Get method.

this error looks strange very strange.

0 likes
10 replies
wontonesaju's avatar

$("#edituser").on('submit',function(ev) { ev.preventDefault();

$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});


$.ajax({
    type:"POST",
    url:"./processuseredits",
    data:$("#edituser").serialize(),
    success:function(html){

      //alert(html);

        KTApp.unblockPage();toastr.options = {
             "closeButton": true,
             "debug": true,
             "newestOnTop": true,
             "progressBar": false,
             "positionClass": "toast-top-right",
             "preventDuplicates": false,
             "onclick": null,
             "showDuration": "300",
                 "hideDuration": "1000",
                 "timeOut": "5000",
                 "extendedTimeOut": "1000",
             "showEasing": "swing",
             "hideEasing": "linear",
             "showMethod": "fadeIn",
             "hideMethod": "fadeOut"
           };
           toastr.success("User detail has been successfully updated.");
           //$("#adduser")[0].reset();


 },
    beforeSend:function(){
         KTApp.blockPage();


    },
    error: function(jqXHR, exception) {
     if (jqXHR.status === 0) {
         alert('Internet connection broken.');
         }
         else if (jqXHR.status == 404) {
         alert('Requested page not found. [404]');
         } else if (jqXHR.status == 500) {
         alert('Internal Server Error [500].');
         } else if (exception === 'parsererror') {
         alert('Requested JSON parse failed.');
         } else if (exception === 'timeout') {
         alert('Time out error.');
         } else if (exception === 'abort') {
         alert('Ajax request aborted.');
         } else {
         alert('Uncaught Error.n' + jqXHR.responseText);
         }
 }

});

});

wontonesaju's avatar

Code is working well if i am using query string with question mark then ajax post works very well. i am thinking html i cant able to paste it here

you can use this

Javascript ajax https://pastebin.com/nXhbDUWu Front end https://pastebin.com/5u71iU9h

Controller https://pastebin.com/fB8J5cME

Route code

Route::get('edituser','UserController@getuser')->middleware('validuser'); Route::post('processuseredits','UserController@doUpdate')->middleware('ajax','validuser');

if i will use edituser/ then in the route like i mentioned above i will use edituser{uid} and in my controller getuser() function i will add one parameter $uid.

But then ajax will not work, it will pop up a error that post method not supported

laracoft's avatar

In that case, can you use the Chrome Developer tools to identify which is the offending URL that caused the not supported exception?

Otherwise you have to show the HTML code for #edituser

laracoft's avatar

Also change url:"./processuseredits", to url:"/processuseredits",

wontonesaju's avatar

"The POST method is not supported for this route. Supported methods: GET, HEAD.",…}

tried already with this way and same error.

laracoft's avatar
  1. Load your form in Chrome
  2. Open Developer Tools (Ctrl+F12)
  3. Click on the Network tab, then XHR sub tab
  4. Click on Clear, which is a No Entry icon
  5. Go back to your form, click on Submit
  6. Go back to Developer Tools
  7. Which is the URL that AJAX failed?

If you fail to identify the URL, please indicate clearly which step above you could not follow.

wontonesaju's avatar

any way thanks it works now ../processuseredits i changed this. it was searching my ajax file inside edituser/ page. i found that a bug.

laracoft's avatar

Glad to hear that. Do pick an answer that helped you best. :)

Please or to participate in this conversation.