JQuery Ajax in Chrome sends GET instead of POST, but in Edge it sends correctly

156
March 14, 2022, at 2:30 PM

The following code triggers a GET Method instead of POST.

$.ajax({type: 'POST',url: 'http://localhost:8000/DoAsync',data: {i:e},dataType: 'script'            
    });

It's happened in Chrome.

But, while I use the same code in Edge, it triggers correctly.

Don't know how to resolve it in Chrome? I've tried to clear the Cache. Also the same result.

Answer 1

When I use http://127.0.0.1:8000/ to access the server, I've received the error in Chrome, but not in Edge.

Whereas http://localhost:8000/ to access the server, performs correctly the POST method in both Chrome and Edge browsers.

So, now I'm using http://localhost:8000/.

Answer 2

The 405 Method Not Allowed and Request Method: GET are a clear sign that the chrome browser use the default method GET.

You can try method: 'POST' instead of type: 'POST' as already mentioned by @aynber, but it would only solve the problem if you are using an old jQuery Version.

See jQuery ajax documentation for more information

'type' is an alias for 'method'. You should use 'type' if you're using versions of jQuery prior to 1.9.0.

Rent Charter Buses Company
READ ALSO
jQuery - how to pass in options to a function that creates a datatable from a JSON object

jQuery - how to pass in options to a function that creates a datatable from a JSON object

I have the following that creates a datatable from a JSON object

110
disable selection after copying in jQuery

disable selection after copying in jQuery

My code to copy the text inside the field:

120
Hi everyone , I am new to jQuery and I was asked this question but I don't know how to do it

Hi everyone , I am new to jQuery and I was asked this question but I don't know how to do it

Ron recently started his carrier in developing web applicationsAs a part of his first project, he is assigned to create a web page using jQuery library

126
Importing jQuery in SvelteKit

Importing jQuery in SvelteKit

How do I import jQuery in SvelteKit (with TypeScript support)?

191