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但无法弄明白。
谢谢
答案 0 :(得分: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);