0

Data from Ajax to console screen, at the same time, when I look at Browser f12 Network, the data returns successfully as follows. But it does not show in div in some kind of index.blade.php file.

Response Json Data

{"options":"<table>\n  <thead>\n    <tr>\n        <th>Alt Grup<\/th>\n        <th>Miktar<\/th>\n    <\/tr>\n  <\/thead>\n  <tbody>\n                      <tr>\n              <td>AB<\/td>\n              <td>110<\/td>\n          <\/tr>\n                  <tr>\n              <td>AC<\/td>\n              <td>9<\/td>\n          <\/tr>\n           \n        \n  <\/tbody>\n<\/table>\n\n\n\n"}

Ajax Script in index.blade.php

<script type="text/javascript">
    $(document).ready(function(){
        $('.depo_sec').click(function(){
        var depo_id = $(this).children('input:hidden').eq(0).val();
            $.ajax({
            url: "{{ route('stok-ajax') }}",
            dataType: 'json',
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            method: 'POST',
            data: {depo_id:depo_id},
            success: function(dataHTML) {
                $('#ajax-area').html(dataHTML);
                console.log(dataHTML);
            }
            });
        });
    });
</script>

I want to display ajax data into the div id="ajax-area".

index.blade.php

<div class="row">
  <div id="ajax-area"></div>
</div>

It does not give any errors but does not print anything on the page.

1 Answer 1

3

Depending on your JSON return, you need

$('#ajax-area').html(dataHTML.options);

instead of

$('#ajax-area').html(dataHTML);

N.B: You should be very careful about that because injecting some HTML is a XSS vulnerability.

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

Comments

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.