10

Why do we have method 'PUT' in AJAX and where is it most used?

Example:

$.ajax({
    url: 'script.php',
    type: 'PUT',
    success: function(response) {
        //...
    }
});

Why didn't the author simply use GET/POST instead?

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
pixlboy
  • 1,452
  • 13
  • 30

1 Answers1

21

For RESTful APIs POST has a specific meaning (create a resource) while PUT has a different one (update an existing resource):

  • GET retrieves a list or an item
  • PUT replaces a collection or an item
  • POST creates a new item in a collection
  • DELETE deletes a collection or an item

However, if there's really "script.php" whoever developed it was not very thorough when creating his API. "script.php" is pretty much not RESTful at all... Usually the URL structure of a proper RESTful API looks e.g. like this:

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636