从当前表单获取动作值到jquery自动保存

时间:2013-08-21 15:04:34

标签: jquery forms autosave

如何从我提交的表单中获取“action”值?

<form accept-charset="UTF-8" action="/outprojects/save_at/10232" class="edit_user" id="edit_user_10232" method="post">

所以我希望jQuery自动保存保存到此操作URL(但默认为当前URL)。

<script type="text/javascript">
jQuery(function($) {
$("form").autosave(
{
  callbacks: {

    scope: 'all',
    trigger: ["change", function() {
      var self = this;
      $("[name=save]").click(function() {
        self.save();
      });
    }],
    save: {
      method: "ajax",
      options: {
        type: 'PUT',
        url: this.getAttribute('action')
      }
    }
  }
});

});

给出错误:

TypeError:this.getAttribute不是函数

1 个答案:

答案 0 :(得分:0)

jQuery(function ($) {
    $("form").autosave({
        callbacks: {
            scope: 'all',
            trigger: ["change", function () {
                var self = this;
                $("[name=save]").click(function () {
                    self.save();
                });
            }],
            save: {
                method: "ajax",
                options: {
                    type: 'PUT',
                    url: $(this).attr('action')
                }
            }
        }
    });
});
相关问题