【问题标题】:Form autosubmit表单自动提交
【发布时间】:2015-09-24 02:44:03
【问题描述】:

blade.php

 <link rel="stylesheet"  href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">

<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script language"javascript" type"text/javascript">

$(document).ready(function(){
  $(".view_parent_furnace_boiler").droppable();
});
    $(document).ready(function() {

    $(".device-container").draggable(
      {

      grid: [10, 10],
        containment: "#picture_container",

        stop: function(){

      /*finding the DMI' id*/
            var elementID = $(this).attr('id');
            var  elementID = elementID.split(",");
            var parent = $(this).parent();

      /*finding the x and y position percentage based on the container*/
            var xPosition = parseInt($(this).css('left'))/parent.width()*100+"%";
            var yPosition = parseInt($(this).css('top'))/parent.height()*100+"%";

            /*assigning the div id to variable for further display and debugging purpose*/
            for (var k = 0; k < elementID.length; k++) {
                var device_id = elementID[0];
                var command   = elementID[1];
                var map_id    = elementID[2];
            }

            /*assigining values to variables*/
            $('#test').val(device_id +',' + ' ' + command + ',' + ' ' + map_id);
            $('#device_id').val(device_id);
            $('#command').val(command);
            $('#map_id').val(map_id);
            $('#PositionX').val(xPosition);
            $('#PositionY').val(yPosition);
        },
        revert: 'invalid'
    });
}); 
</script>

这是我的表格

{{Form::open()}}
<div>
  <div class="well">

    {{ Form::text('device_id', '',  ['id'=>'device_id', 'style'=>'color:black']) }}
    {{ Form::text('command', '',    ['id'=>'command', 'style'=>'color:black']) }}
    {{ Form::text('map_id', '',     ['id'=>'map_id', 'style'=>'color:black']) }}
    {{ Form::text('x_position', '', ['id'=>'PositionX', 'style'=>'color:black']) }}
    {{ Form::text('y_position', '', ['id'=>'PositionY', 'style'=>'color:black']) }}


    {{ Form::submit('Save','', ['style'=>'color:black'] ) }}

  </div>
</div>

{{Form::close()}}

BuildingController.php

if(count((array)Input::all()) ) {

  $dmi = DashboardMapItem::where('map_id', Input::get('map_id'))
    ->where('device_id', Input::get('device_id'))
    ->where('command', Input::get('command'))
    ->first();
  // dd($dmi->toArray());
  $dmi->x_position = Input::get('x_position');
  $dmi->y_position = Input::get('y_position');
  if( $dmi->save() ) {
    Session::flash('success', 'DMI Updated');
    return Redirect::back();
  }
}

如果有人帮助我,我会很高兴,

我正在尝试自动提交而不是提交按钮本身。我一直在寻找,但我找不到解决方案。我尝试使用ajax,但无法弄清楚。

谢谢

【问题讨论】:

  • 自动提交是什么意思?要是能说的清楚点就好了。
  • 我有一张背景图片,我展示了一些带有一些属性的元素。我想在容器中移动这些元素,并希望将 x 和 y 位置保存回表中。提交按钮工作正常,但我必须在移动其他元素之前点击提交按钮。
  • 我刚刚上传了页面的图片。这是我正在谈论的元素imgur.com/wfug4N1。请帮忙

标签: javascript php html ajax laravel-4


【解决方案1】:

我会尝试类似的方法。 AJAX 到底有什么问题?

$('#yourform').on('submit', function(e) {
    e.preventDefault();
    var form = $(this);

    $.ajax({
        type: form.prop('method'),
        url: form.prop('action'),
        data: form.serialize(),

        success: function(result) {
        alert('success');
        }
    }
    });

});

...我会在你的 stop 事件的末尾添加这个:

$('#yourform').submit();

编辑:当然,您还需要从控制器发送正确的响应:

return Response::json('success', 200);

【讨论】:

  • 对不起,我回来晚了!如果我添加该功能,则查询代码不起作用。为什么你这样想?当我添加你的代码时元素不会移动!
猜你喜欢
  • 1970-01-01
  • 2018-01-15
  • 2013-03-15
  • 2011-02-05
  • 2010-11-25
  • 2015-05-14
  • 1970-01-01
相关资源
最近更新 更多