Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

zgabievi's avatar

php 5.6 & ajaxSetup post request problem

I had ajax request. It was working in previous version of PHP. Now it's not working. Any suggestions?

In

<meta name="csrf-token" content="{!! csrf_token() !!}" />

list of data:

<ul class="panel__list panel__list--sortable record" data-url="{!! route('admin.pages.order') !!}">
    @foreach($pages->sorted()->get() as $index => $page)
        <li class="record__item record__item--draggable clear" data-order="{{ $page->id }}">
            {content}
        </li>
        <!-- record__item clear -->
    @endforeach
</ul>
<!-- record -->

AJAX:

var $parent = $(element.item).parent('.panel__list--sortable');
var order = [];

var $items = $parent.find('.record__item--draggable');
$.each($items, function (index, item) {
    order.push($(item).data('id'));
});

$.ajaxSetup({
    global: false,
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});

$.ajax({
    url: $parent.data('url'),
    type: "POST",
    data: {
        order: order
    }
});

Controller Method:

/**
 * @param Request $request
 */
public function order(Request $request)
{
    foreach ($request->get('order') as $index => $id) {
        \App\Page::find($id)->update(['sort' => $index + 1]);
    }
}

And I'm getting error:

Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead. in Unknown on line 0

Warning: Cannot modify header information - headers already sent in Unknown on line 0
0 likes
1 reply
ohffs's avatar

Have you tried doing the change to php.ini that the error tells you to do and restarting your webserver/php?

Please or to participate in this conversation.