我的API PUT无法正常工作

时间:2018-06-27 14:02:46

标签: javascript json api

我无法让ajax执行“ PUT”操作。

$('.thetest').click(function() {
  console.log("Script executed");
  $.ajax({
    url: 'redacted for obvious reasons',
    contentType: 'application/json',
    success: function(result) {
      alert("success?");
    },
    type: 'PUT',
    data: {
      "userId": "also redacted",
      "data": {
        "userSettings": {
          "notificationSettings": {
            "Marketing": false,
            "Newsletters": true

          }

        }
      }
    },

  });

});
<button class="thetest"> PRESS ME</button>

一旦按下按钮,console.log就会触发。因此,我知道脚本正在使用中,只是不会发送到API。

有什么想法吗?

1 个答案:

答案 0 :(得分:-1)

将类型更改为方法

 $('.thetest').click(function () {
            console.log("Script executed");
            $.ajax({
                url: 'redacted for obvious reasons',
                contentType: 'application/json',
                success: function (result) {
                    alert("success?");
                },
                method: 'PUT',
                data: {
                    "userId": "also redacted",
                    "data": {
                        "userSettings": {
                            "notificationSettings": {
                                "Marketing": false,
                                "Newsletters": true

                            }

                        }
                    }
                },

            });

        });