weixin_33736832 2017-02-01 11:05 采纳率: 0%
浏览 33

AJAX不提交表格

This does prevent the form from posting. That what preventDefault does I understand. However the update() function doesn't send the form to the URL provided. I don't understand why?

UPDATE: I have the same script working on other project. I think problem is in my html. I can't figure it out though!

<form method="post" id="Name" action="updateContent.cshtml" class="abc hidden">
  <input name="currentInput" type="text" class="navbar-brand logo" value="@content.Name" />
  <input type="submit" name="currentPlaceHolder" value="Name" class="hidden" />
</form>
$(function () {
   $('.abc').submit(function (ev) {
     var frm = $(this);
     update(frm);
     ev.preventDefault();
   });
});

function update(frm) {
  $.ajax({
    type: frm.attr('method'),
    url: frm.attr('action'),
    data: frm.serialize(),
    success: function (data) {}
  });
}
  • 写回答

3条回答 默认 最新

  • weixin_33738555 2017-02-01 11:12
    关注

    Your form has no method. If you don't provide a type value to the $.ajax() call then the request will not be sent and the error method will immediately be invoked.

    Here's an example of this behaviour: https://jsfiddle.net/csw0tu69/

    To fix this, simply give the form a method:

    <form method="post" id="Name" action="updateContent.cshtml" class="abc hidden">
    

    Working example

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog