samedi 19 août 2017

Correct userid not getting sent during post event

Hi I hope someone can help I have a gifts plugin which is not including the userid in the request and therefore fails to work, bellow is my js code. When I check the request body viewed in the console shows

to_user=&gift_id=18&msg= as you can see no userid is being sent for to_user

In my console view if I add to_user=532&gift_id=18&msg= and then posts the gift is sent as expected.

This is the code on the modal popup

<script type="text/javascript">
if(  false  ){
 $('#gift-modal').show();
}
$('.giftimage').on('click',function(){
$('.giftimage').removeClass('activegift');
$(this).addClass('activegift');
})
$('#send_gift').on('click',function(){
var gift = $(this).parent().parent().find('.giftimage.activegift');
var gift_price =gift.data('price');
var gift_id =gift.data('giftid');
var msg='';
            data={to_user: $('#userid_gift').val() ,  gift_id:gift_id , msg:msg};
                $.ajax({
                          type: "POST",
                              url: "http://ift.tt/2igH4Q5",
                              data: data,
                              success: function(data){

                                   toastr.success(data.message);                               window.location.reload();                                        

                              },
                              error: function(XMLHttpRequest, textStatus, errorThrown) {
                                    toastr.error("Some Error");
                              }                               
               });  
})
</script>

This is the code from the send_gift.blade.php

@parent

<script>
$('#giftmodal').on('click',function(){

    $('#userid_gift').val('<?php echo e($user_id); ?>');
    $('.gift_header').text("}");
})
</script>

This is the modal code

<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
  <div class="modal-header" style="background:#007BE6">
    <button type="button" class="close" data-dismiss="modal">&times; </button>
    <h4 class="modal-title gift_header">}</h4>
  </div>
  <div class="modal-body">
     @foreach($gifts as $gift)
 <div style="display: inline-block;height: 70px;width: 70px;    margin: 25px;">
<img class="giftimage" data-price="}" data-giftid="  }" src=} />
<span class="grey">} }  </span>
</div>
@endforeach
   <div id="gifts-message" class="gifts-msg gifts-msg--visible"> <input type="text" name="msg" id="gift_text" class="input input--sm" placeholder="">  </div>
  </div>
  <div class="modal-footer">
<!--         <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> -->
<input  type="hidden" id="userid_gift" value='' />
    <button type="button" class="btn btn-default " id="send_gift"  style="margin: 0" data-dismiss="modal">}</button>
  </div>
  </div>
 </div>
</div>

Any suggestions on how I can get this to work?

EDIT I have made some progress if I edit this line

  <input  type="hidden" id="userid_gift" value='#userid_gift' />

it still fails as the value has a % sign for the first digit in my console view I can see to_user=%23userid_gift&gift_id=19&msg=

the number should be 523 any idea why its changing the 5 to a % sign

thanks



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2fV1g9o
via IFTTT

Aucun commentaire:

Enregistrer un commentaire