gpt4 book ai didi

javascript - 表单自动提交

转载 作者:行者123 更新时间:2023-12-03 09:38:34 24 4
gpt4 key购买 nike

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但无法弄清楚。

谢谢

最佳答案

我会尝试类似的事情。您在使用 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();

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

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

关于javascript - 表单自动提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31254556/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com