Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Diff between type and method in ajax

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.

like image 851
Mr world wide Avatar asked Apr 21 '17 12:04

Mr world wide


People also ask

What is type in AJAX?

$.ajax({name:value, name:value, ... }) Parameters: The list of possible values are given below: type: It is used to specify the type of request. url: It is used to specify the URL to send the request to.

What is the use of AJAX () method?

The ajax() method is used to perform an AJAX (asynchronous HTTP) request. All jQuery AJAX methods use the ajax() method. This method is mostly used for requests where the other methods cannot be used.

What is difference between dataType and content type in AJAX?

From https://api.jquery.com/jQuery.ajax/ you see that contentType is to tell what you send while dataType is what you would like as a response (and the response includes a content-type as well so that you can check what is actually sent back).

What is the difference between GET and POST method in AJAX?

GET is basically used for just getting (retrieving) some data from the server. Note: The GET method may return cached data. POST can also be used to get some data from the server. However, the POST method NEVER caches data, and is often used to send data along with the request.


2 Answers

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/

like image 51
Stefdelec Avatar answered Sep 19 '22 16:09

Stefdelec


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. 
like image 42
Hossam Avatar answered Sep 20 '22 16:09

Hossam