How do I PUT data to Rails using JQuery

前端 未结 6 953
半阙折子戏
半阙折子戏 2020-11-30 00:32

I am trying to send a jquery ajax PUT request that looks like this:

$.ajax({
          type: \"PUT\",
          url: \'/admin/pages/1.json\',
          data:         


        
6条回答
  •  悲哀的现实
    2020-11-30 00:48

    PUT and DELETE are not supported by all browsers, RubyOnRails supports passing an extra parameter with your data called _method which will indicate how RoR will treat the request.

    $.ajax({
              type: "POST",
              url: '/admin/pages/1.json',
              data: { _method:'PUT', page : {...} },
              dataType: 'json',
              success: function(msg) {
                alert( "Data Saved: " + msg );
              }
    });
    

提交回复
热议问题