通过ajax

时间:2019-01-10 07:04:47

标签: javascript ajax laravel

在这种情况下,我正在模态内执行消息线程。我想使用其参考编号显示特定人员的消息线程。我的问题是我无法将参考号传递给控制器​​并返回刀片服务器(在消息线程中)。这是我的密码。

我的消息线程模式

<div id="threadmessage" class="modal fade" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h3>Message Thread</h3>
            </div>
            <div class="modal-body" style="height: 300px;" >
                <div class="row" style=" margin-left: 30px; margin-bottom: 5px; left: 20px; width: 550px; height: 200px; overflow: auto;">
                     <div>
                       @foreach ($messageThread as $thread)

                               {!!$thread->message!!}
                               <br>
                       @endforeach
                </div>
                <br>
                </div>
                <div>
                    <br>
                    <div class="col-md-2"> 
                        <b> Message: </b><br>
                    </div>
                    <div class="col-md-10"> 
                        <textarea required=" " id="messageContent" style="resize: none;" class="form-control" rows="2"></textarea>
                    </div>
                </div>
                <br>
            </div>
            <div class="modal-footer">
                <div>
                    <button type="button" id="btn-message" class="btn btn-default" data-dismiss="modal" style="background-color: #3c5fa6; color: white;"> 
                        Send <i class="fa fa-paper-plane-o ml-1"> </i>
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>

我的Javasript用于显示消息模式

$('#inquire_t tbody').on('click','#showMsg-btn',function(){
   var flag = 6;   // Approved
   var refNumber = $(this).attr('value');
   var cur_flag = $(this).attr('name');
   var user = $("#username").html();
   console.log(refNumber);
   console.log(user);
   $('#threadmessage').modal({"backdrop":"static"});


   getMessage(refNumber, user);
});//btn-message

function getMessage(num, name){
    var refNumber = num;
    var username = name;

    $.ajax({
        url:'getAllMessage',
        type: 'GET',
        headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
        data: refNumber+'refNumber'+username+'&username',
        // dataType:'TEXT',
        success: function(data){
        }
   })
}

模态按钮

用于获取消息的控制器

public function getAllMessage(Request $request){
    $refNumber = $request->get('refNumber');
    $number = $refNumber;
    $messageThread = DB::table('i_di_thread')->select('message')->where('refNumber', '=', $number)->get();
    return view ('message', ['messageThread'=>$messageThread]);
} 

我的路线

Route::get('showInquiries','HomeController@getAllMessage');
Route::get('getAllMessage','HomeController@getAllMessage');

1 个答案:

答案 0 :(得分:0)

您可以通过两种方法传递它,并且您的数据未正确连接,因此:

方法1:

$.ajax({
        ...
        data : { 'refNumber' : refNumber, 'username' : username },
        ...
});

方法2:

data:'refNumber='+ refNumber + '&username='+ username