Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过Ajax将HTML内容发布到PHP_Php_Jquery_Mysql_Html_Ajax - Fatal编程技术网

通过Ajax将HTML内容发布到PHP

通过Ajax将HTML内容发布到PHP,php,jquery,mysql,html,ajax,Php,Jquery,Mysql,Html,Ajax,我正在通过AJAX将HTML内容发布到PHP。在调试过程中,我看到ajax从编辑器发布了全部内容。但当我检查数据库时,我看到40-50%的发送内容。在php中使用以下函数过滤发送的数据。我的数据库字段类型是长度为0的文本 function html($data, $db) { $data = htmlentities($data); $data = $db->escape_string($data); return $data; } 没有成功。但当我试图发布标准文本内容(

我正在通过AJAX将HTML内容发布到PHP。在调试过程中,我看到ajax从编辑器发布了全部内容。但当我检查数据库时,我看到40-50%的发送内容。在php中使用以下函数过滤发送的数据。我的数据库字段类型是长度为0的文本

function html($data, $db)
{
$data = htmlentities($data);        
$data = $db->escape_string($data);
return $data;
}

没有成功。但当我试图发布标准文本内容(非html)时,它会将整个内容发布到db表中。如何处理这个问题?有什么建议吗

JS

function postViaAjax(autosaveMode) {
    var name = $("#name").val();
    var title = $("#title").val();
    var menu = $("#menu").val();
    var parentcheck = $(".parentcheck:checked").val();
    var id = $("#id").val();
    if (parentcheck == 0) {
        var parent = parentcheck;
    } else {
        var parent = $("#parent").val();
    }
    var content = CKEDITOR.instances['content'].getData();
    var dataString = 'name=' + name + '&title=' + title + '&menu=' + menu + '&parentcheck=' + parentcheck + '&id=' + id + '&parent=' + parent + '&content=' + content;
    $.ajax({
        type: "POST",
        url: "processor/dbadd.php",
        data: dataString,
        dataType: "json",
        success: function (result, status, xResponse) {
            var message = result.msg;
            var err = result.err;
            var now = new Date();
            if (message != null) {
                if (autosaveMode) {
                    $('#submit_btn').attr({
                        'value': 'Yadda saxlanıldı ' + now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds()
                    });
                } else {
                    $.notifyBar({
                        cls: "success",
                        html: message + ' ' + now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds()
                    });
                }
            }
            if (err != null) {
                $.notifyBar({
                    cls: "error",
                    html: err
                });
            }
        }
    });
};

我想你可能想错了。您使用回调函数的PHP脚本将接收您告诉它要接收的所有数据

如果您使用的是jQuery之类的库,则可以进行如下设置:

    var formValues = $(this).serialize();
    $.ajax({
        url: 'yourFile.php?'+formValues,
        dataType: 'json',
        success: function(data){
            console.log(data);
        }
    }); 
    return false;
然后你只需要让你的php脚本获取正在发送的数据。你可以通过POST或GET实现这一点,这完全取决于你自己,也取决于你在做什么


我希望这能帮助你开始。

很可能是因为你在发布“内容”时需要避开它

试一试


在将其附加到数据字符串之前

请发布发布数据的javascript代码。可能您的db字段的文本大小有限?当我尝试发布标准文本内容(非html)时,它会将整个内容发布到db表中。为什么要通过
htmlentities()运行它
以及为DB转义它?得到这样的输出。插入和输出时需要从哪些函数传递数据?我现在知道什么是序列化,我的函数做完全相同的事情。我不使用serialize,因为我使用的是CKeditor<代码>var content=CKEDITOR.instances['content'].getData()以获取编辑器数据
content = encodeURIComponent(content) 
content = encodeURI(content)