0

送信時に AJAX 呼び出し用に処理されるフォームがあります。他の HTTP 動詞を使用するには、フォーム
express.js
<input type="hidden" name="_method" value="put">

AJAX呼び出しがtype: "PUT"あり、サーバー側に送信されると404Cannot PUT.

PUTAJAX またはフォームがリクエストに対して正常に送信する必要があるものは他にありますか?
助言がありますか?

ルート/index.js

app.put('/:library/:book/:genre/', function(req, res) {
  console.log(req.params.genre);
  res.send(200, {"youKnow":"putter"});  
});

libraryBookForm.jade

form#create-library-form(action='#', method='post')
      input(name="_method", value="PUT", type="hidden")
      div
        label Book
        input#book-name(type='text', name='book-name', required='required')
      div
        label Gender
        select#book-genre(name='book-genre')
          option(value='scifi') SciFi
          option(value='fantasy') Fantasy
      div
        input(type='submit', id='create-book-submit', value='Create Book')

libraryBookAjax.js

    event.preventDefault();
    $.ajax({
      url: '/publicLibrary/drawingBook/fantasy'
      type: 'PUT',
      contentType: 'application/json: charset=utf-8',
      dataType: 'json',
      data: form.serialize()
    }).done(function(msg) {
      alert("put success: " + msg);
    }).fail(function(msg) {
      console.log("failure: " + msg);
    });

type: "POST"AJAXリクエストでも試しました。その場合、POSTリクエストはルートではなくルートapp.putで送信および実行されます。

4

1 に答える 1