JQuery Ajax is sending GET instead of POST

前端 未结 11 530
野性不改
野性不改 2020-12-03 00:20

The following code triggers a GET instead of a POST HTTP request.

function AddToDatabase() {
  this.url = \'./api/add\';
}

AddToDatabase.prototype.postData          


        
11条回答
  •  無奈伤痛
    2020-12-03 01:02

    I noticed this behavior as well where my POST was sending a GET. The scenario's pretty unique, but maybe it will help someone.

    This was happening to me on my User Role-edit page, where I was using ajax (post) as an immediate action when a role was checked or unchecked.

    I also had the server configured to re-authenticate the user (and redirect them) whenever their role information changed so that their claims would be refreshed.

    The brutal cycle ended up as:

    1. First Role Update -- POST -- 200 success

    2. Next Role Update -- POST -- 302 Found -> Redirect (I did not notice this until I used Fiddler rather than Chrome's network monitor)

    3. Redirect Call from (2) (Same URL) -- GET -- 404 Not Found (since I only allowed Post)

    4. GOTO (1)

    I ended up changing the server to bypass re-authentication/claims update when it detected an ajax request (based on the Accept Types).

提交回复
热议问题