Move user when click on chat Button to chat page with AJAX| IMPORTANT

前端 未结 1 431
北恋
北恋 2021-01-29 10:47

In my web , there is \"message\" button in every user profile , so when any user click on \"message \" button , it should to move him to \"message\" page with ajax .

1-

相关标签:
1条回答
  • 2021-01-29 11:14

    Instead of creating AJAX request, you can submit user details to controller. Where view is getting loaded.

    $("#startMessage").click(function(){
        var user_id = $("#user_id").val();
        /*
         * AJAX request won't work here, because you had sent user_id data to controller "Message/index" using AJAX, 
         * then in it's success method you are again redirecting to page controller "Message/index", here user_id details are not present
         * Instead will just create a form and submit that form to controller "Message/index", so that variable user_id will available in "Message/index"
         * Once form submitted to controller Message/index, view "front/Message_View" was already getting loaded their as per existing code
        */
        var formHTML = '<form name="frmUserData" action="<?php echo base_url('Message/index')?>" method="post">'+
                            '<input type="hidden" name="user_id" value="'+ user_id +'">'+
                       '</form>';
        var formObj = $('.main-footer').append(formHTML).find("[name='frmUserData']");
        $(formObj).submit();
    });
    
    0 讨论(0)
提交回复
热议问题