What is the Diff between type and method in ajax
Asked Answered
L

4

33

HI i have used both the things in my experience i was thinking method and type both are POST and GET methods.

But seems like they are not similar.?

if i use type it is working i am serializeing a form data..

if i write method it is not working can can anyone explain what is the diff between them..?

$.ajax({
  url: "controller.php",
  type: 'POST',
  method: "POST",
  dataType: "json",
});

help is appropriated.

Lacerate answered 21/4, 2017 at 12:50 Comment(0)
T
29

type (default: 'GET') Type: String An alias for method. You should use type if you're using versions of jQuery prior to 1.9.0.

http://api.jquery.com/jquery.ajax/

Tachograph answered 21/4, 2017 at 12:53 Comment(0)
D
22

From: http://api.jquery.com/jquery.ajax/

method:

The HTTP method to use for the request (e.g. "POST", "GET", "PUT"). (version added: 1.9.0)

type:

An alias for method. You should use type if you're using versions of jQuery prior to 1.9.0.
Digraph answered 21/4, 2017 at 12:54 Comment(0)
D
6

both are same, in new version of jQuery type renamed to method

Dyewood answered 21/4, 2017 at 13:26 Comment(0)
S
0

In the code you provided, there doesn't seem to be any issue with the usage of the method property in the $.ajax function. However, there is redundancy in specifying both type and method properties with the same value ("POST").

The method property is an alias for the type property in the $.ajax function, so specifying both properties with the same value is unnecessary. You can remove either type or method from your code, and it will still work correctly. Here's an example:

$.ajax({
  url: "controller.php",
  method: "POST",
  dataType: "JSON",
});

or

$.ajax({
  url: "controller.php",
  type: "POST",
  dataType: "JSON",
});
Schlueter answered 30/6, 2023 at 4:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.