简体   繁体   English

$ HTTP_RAW_POST_DATA错误-未发布数据

[英]$HTTP_RAW_POST_DATA Error - Not posting data

I am trying to perform an AJAX request through jquery-confirm plugin loading the file data from a form through its ajax-load function and then updating the information to a PHP file and ultimately to a database. 我试图通过jquery-confirm插件执行AJAX请求,并通过其ajax-load函数从表单加载文件数据,然后将信息更新为PHP文件,最后更新为数据库。

However, this is resulting in the following 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

I have attempted to even throw in a blank variable as the meaning of this error is it not POSTing the data across to the page. 我什至试图抛出一个空白变量,因为此错误的含义是它没有将数据发布到页面上。 This simply throws back an undefined index, confirming that it isn't posting the data. 这只是抛出未定义的索引,从而确认它没有发布数据。

Some posts on this site have said to change the php.ini files etc, as I am using a university server, we do not have access to change these files. 该站点上的某些帖子说要更改php.ini文件等,因为我使用的是大学服务器,所以我们无权更改这些文件。

Here is my JS file which is performing the AJAX function 这是我的执行AJAX功能的JS文件

function addSubject(){
    $("#addBtn").on('click', function() {     
        $.confirm({
            title: 'Manage Subjects',
            content: 'url: addSubjectForm.html',
            buttons: {
                addSubject: {
                    text: 'Add New Subject',
                    btnClass: 'btn-info',
                    action: function () {
                        var findSubject = this.$content.find('input#newSubject');
                        var findDescript = this.$content.find('input#newDescript');

                        var newSubject = findSubject.val();
                        var newDescript = findDescript.val();

                        if (newSubject === '' || newDescript === '') {
                            $.alert({
                               content: 'One of the fields from the form was empty',
                               type: 'red'
                            });
                            return false;
                        } else {
                            $.ajax({
                                url: "../ajax/admin/addSubject.php",
                                type: "POST",
                                data: {title: newSubject, description: newDescript, blank: 'blank'},
                                cache: false,
                                contentType: false,
                                processData: false,
                                success: function (result) {
                                    $.alert({
                                       content: result,
                                       type: 'green'
                                    });
                                }
                            });

                            console.log(newSubject + " " + newDescript);
                        }
                    }    
                },
                close: {
                    text: 'Close',
                    btnClass: 'btn-danger'
                }
            } 
        });
    });
}

The PHP page where I access the variables is here: 我访问变量的PHP页面在这里:

<?php

$title = filter_input(INPUT_POST, "title");
$description = filter_input(INPUT_POST, "description");

$test = $_POST['blank'];

echo $test;

echo "$title $description";

The blank variable in these files are simply for testing purposes only. 这些文件中的空白变量仅用于测试目的。

Thanks in advance. 提前致谢。

As said in the warning $HTTP_RAW_POST_DATA is deprecated, instead use: 如警告中所述,不建议使用$ HTTP_RAW_POST_DATA,而应使用:

$raw_post_body = file_get_contents("php://input");

For reading raw body content. 用于读取原始内容。

But from what I can see in JS code you're sending a normal www-url-encoded form so use of $_POST is recommended. 但是从我在JS代码中看到的信息来看,您正在发送常规的www-url编码形式,因此建议使用$ _POST。 If it still doesn't work, please do a var_dump or print_r on $_POST so you can debug if really nothing is sent over POST request. 如果仍然不起作用,请在$ _POST上执行var_dump或print_r,以便您可以调试是否确实没有通过POST请求发送任何内容。

Try : 尝试:

$title = filter_input(INPUT_POST, 'title', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); $ title = filter_input(INPUT_POST,'title',FILTER_DEFAULT,FILTER_REQUIRE_ARRAY); $description = filter_input(INPUT_POST, 'description', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); $ description = filter_input(INPUT_POST,'description',FILTER_DEFAULT,FILTER_REQUIRE_ARRAY);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM