在我的视图中,我有通过post方法发送的表单。
我有javascript rateyo我想发送评级变量到张贴方法
在我发送提交后,将我的表格放在一起
$(document).ready(function() {
$(function() {
var $rateYo = $("#rateYo").rateYo({
rating: 2,
fullStar: true
});
$("#getRating").click(function () {
/* get rating */
var rating = $rateYo.rateYo("rating");
window.alert("Its " + rating + " Yo!");
});
});
});
在这里,我需要var评级发送后,我通过后提交表格
这是我的表格
<form class="form-horizontal" role="form" method="POST" action="{{ URL::to('index/saveedit') }}">
<input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
<div class="form-group">
<label class="col-lg-3 control-label">Title:</label>
<div class="col-lg-8">
<input class="form-control" value='{{ $words->first()->title }}' type="text" name="title" readonly="readonly">
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Meaning:</label>
<div class="col-lg-8">
<input class="form-control" value="{{ $words->first()->meaning }}" type="text" name="meaning">
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Rating:</label>
<div class="col-lg-8">
<div id="rateYo"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/rateYo/2.0.1/jquery.rateyo.min.js"></script>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label"></label>
<div class="col-md-8">
<input class="btn btn-primary" value="Save Changes" type="submit">
<span></span>
</div>
</div>
</form>
有很多关于这方面的在线指南
http://www.tutorials.kode-blog.com/laravel-5-ajax-tutorial
在具体回答这个问题时,
以及其他输入表单的数据将被发送?
你的问题似乎是关于用jQuery和附加一个非表单变量来做AJAX文章。您可以在表单上使用jQuery的jQuery.post
和jQuery.fn.serialize
轻松完成此操作。
https://api.jquery.com/jquery.post/https://api.jquery.com/serialize/
请注意.serialize()对数据进行编码,因此需要将额外信息附加到上,就好像它是一个数据字符串一样。
var formURL = "/my-url";
var formData = $("#form").serialize();
// The important bit. Add custom data like URL strings.
formData += "&customVariable=foobar";
$.post({
url: formURL,
data: formData,
dataType: 'json',
success: function (data) {
console.log("Success.", data);
}
);
这将把"customVariable"项添加到您的输入中,以便在控制器中使用。
请参阅:我可以使用jQuery';s serialize()和$.post请求中的一个附加变量?