0

i my view i have form sent by post method.

and i have javascript rateyo i want to send rating variable to post method

together my form after i send submit

$(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!");
        });
    });




});

here i need var rating to send after i submit form by post

here is my form

 <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>
Slatan-ko
  • 248
  • 1
  • 6
  • 18

1 Answers1

0

There are many online guides for this.
http://www.tutorials.kode-blog.com/laravel-5-ajax-tutorial

In reply to this question specifically,

and data form other input form will sent ?

It seems like your question is specifically about doing an AJAX post with jQuery and appending a non-form variable as well. You can do this easily using jQuery's jQuery.post and jQuery.fn.serialize on the form.
https://api.jquery.com/jquery.post/ https://api.jquery.com/serialize/

Be aware that .serialize() encodes your data, so you will need to append extra information on as if it were a data string.

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);
  }
);

This will add the "customVariable" item to your input to work with in the controller.

See: can I use jQuery's serialize() and an additional variable in a $.post request?

Community
  • 1
  • 1
Josh
  • 2,947
  • 1
  • 15
  • 29