1

From View Page I am calling Ajax to my Controller, from my Controller I want to create a html data so I am passing my array to View file to create a HTML data. I don't know why when I try to do console nothing gets return, can anyone tell me where I am going wrong

CallingAjaxFromViewFile

function AjaxgetCheckInChekOutUser(status){
    var url = "{{ url('admin/events/ajaxData') }}";
    var token = $('#token').val();
    if(status){
        $.ajax({
                headers: {
                'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
                },
                url: url,
                type: 'POST',
                data: {'status': status,'_token':token},            
                success: function (data) {
                    alert(data);
                    data = JSON.parse(data);      
                        console.log(data.html);
                        $('#gymimages').html(data.html);
                    
                }
        });
    }
}

myControllerFile

public function AjaxCurrentPastFutureData($data, $status){
    $title = "HDTuto.com";  

    $html = view('admin.events.ajaxdataview')->with(compact('title'))->render();
    //pr($html);
    $response = response()->json(['success' => true, 'html' => $html]);
    return $response;
}

NowmyViewFile From Where I append HTML Data

<h1><i>{{ $title }} </i></h1>

Can anyone tell me where I am going wrong?

2
  • What are you getting in your request? check in your network XHR request. This way you'll know what you're passing and what response you're getting Commented Feb 28, 2018 at 10:30
  • When I am pr($data); it is printing bt only thing is not returning Commented Feb 28, 2018 at 10:56

1 Answer 1

4

** Use this**

function AjaxgetCheckInChekOutUser(status){
var url = "{{ url('admin/events/ajaxData') }}";
var token = $('#token').val();
if(status){
    $.ajax({                
            url: url,
            type: 'POST',
            data: {'status': status,'_token':token},            
            success: function (data) {                    
                    $('#gymimages').html(data.html);
            }
    });

Also update your Controller function

public function AjaxCurrentPastFutureData(Request $request){
    $title = "HDTuto.com";  
    $html = view('my')->with(compact('title'))->render();
    //pr($html);
    $response = response()->json(['success' => true, 'html' => $html]);
    return $response;

}

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you this solved my issue I was doing it all wrong first but then followed your code and everything is working fine Thank you so much you saved my day

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.