猿问

通过ajax提交表单时启用浏览器自动完成

谷歌搜索一段时间后,我找不到解决我问题的好答案。


我有一个使用模态窗口(例如引导框)显示的表单。此表单使用ajax post 提交,但浏览器无法存储输入值(自动完成),以便在再次显示此表单时显示这些值。


function openModal(view) {

  var buttons = {};


  buttons.success = {

    label: "Salvar",

    className: "btn-primary",

    callback: function() {

      var $form = box.find("form");

      var valuesToSubmit = $form.serialize();

      $.ajax({

        type: "POST",

        url: $form.attr('action'),

        data: valuesToSubmit,

        dataType: "json"

      }).success(function(response) {

        box.modal('hide');

        if (successCallback) {

          successCallback();

        }

      }).error(function(response) {

        box.find(".modal-body").html(response.responseText);

        enableBasicControls(box);

        if (errorCallback) {

          errorCallback();

        }

      });


      return false;


    }

  };


  buttons.danger = {

    label: "Cancelar",

    className: "btn-danger"

  };


  box = bootbox.dialog({

    title: title,

    animate: false,

    message: view,

    onEscape: function() {},

    buttons: buttons,

    size: "large"

  });

}

<form asp-action="Create">

    <input asp-for="Id" type="hidden" />

    <input asp-for="ConsultaId" type="hidden" />


    <div class="row">

        <input data-focus="true" data-select="true" class="form-control" type="number" data-val="true" data-val-required="The QtdEmbalagens field is required." id="QtdEmbalagens" name="QtdEmbalagens" value="1">

        

    </div>

    <div class="row">

        <input rows="4" class="form-control" type="text" id="Observacao" name="Observacao" value="">

    </div>

</form>


潇湘沐
浏览 183回答 1
1回答

当年话下

我使用 iframe 解决了提交到虚假页面的问题:<iframe name="myframe" id="frame1" src="Create" style="display: none;"></iframe><form asp-action="Create" target="myframe">&nbsp; &nbsp; <input asp-for="Id" type="hidden" />....function openModal(view) {&nbsp; &nbsp; var buttons = {};&nbsp; &nbsp; buttons.success = {&nbsp; &nbsp; &nbsp; &nbsp; label: "Salvar",&nbsp; &nbsp; &nbsp; &nbsp; className: "btn-primary",&nbsp; &nbsp; &nbsp; &nbsp; callback: function () {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var $form = box.find("form");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var&nbsp; url = $form.attr('action');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $form.attr('action', "about:blank");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $form.submit();//======================== fake&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var valuesToSubmit = $form.serialize();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $.ajax({&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type: "POST",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; url: url, //sumbits it to the given url of the form&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data: valuesToSubmit,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dataType: "json"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ...
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答