javascript - post方法不发送全文

标签 javascript php jquery mysql ajax

我有一个存储过程可以同时向数据库发送和获取博客数据:

CREATE DEFINER=`root`@`localhost` PROCEDURE `post_and_fetch_ans`(
    IN answerbody longtext,
    IN postid int,
    IN answerer int)
BEGIN
   INSERT INTO `login`.`answers` (answer_body,userpost_post_id,users_user_id) VALUES (answerbody,postid,answerer);
   SELECT * FROM `login`.`answers` WHERE userpost_post_id = postid  ORDER BY answer_date DESC LIMIT 1;
END

但我的问题是我在文本编辑器上写的文本数据量,只有几行被发送并存储到数据库。我正在使用 ajax 将数据发送到 php 页面,该页面将其存储到数据库。

$('#answerform').submit(function(event){
   event.preventDefault();
   var data='answer_body='+CKEDITOR.instances.content.getData()+'&userpost_post_id=<?php echo $contents[0]->post_id;?>&users_user_id=<?php echo $userdata->user_id; ?>';
   alert(data);

   $.ajax('../includes/verifyanswer.php',{
        data:data,
        type:"POST",
        datatype:'json',
        success:function(response){
            alert(response);

            var obj=$.parseJSON(response);

            $('#mainanswer').hide();
            $('#answerform').hide();
            $('#answerthisquestion').show();
            var str="<div class='styleanswer' >"+obj[0]['answer_body']+'</div><hr>';

            $('#answerwrapper').append(str);
            $('#answerwrapper pre code').each(function(i, block) {
                hljs.highlightBlock(block);
            });
        },
        error:function(response){
            alert(response);
        }
    });
}); 

verifyanswer.php 页面是:

require_once '../core/init.php';
$answer=$_POST['answer_body'];

$post_id=$_POST['userpost_post_id'];
$answerer=$_POST['users_user_id'];

if(isset($answer,$post_id,$answerer)){
    if(!empty($answer) && !empty($post_id) && !empty($answerer)){
        $db = DB::getInstance();
        $result = $db->post_and_fetch("CALL login.post_and_fetch_ans(?,?,?)",array($answer,$post_id,$answerer))->result();
        echo json_encode($result);
    }
}

这条线

$answer=$_POST['answer_body'];

仅包含部分(比实际文本少得多)文本,而不是完整文本。因此数据库中存储的文本较少

问题的一个例子是

我将这段文本发送到数据库中存储

enter image description here

但我只得到存储在数据库中的这几行文本

Congratulations to Mathematics SE for being the first site to unlock this hat, less than 18 hours into the event! Also to Code Review SE and Blender SE for technically needing only three users each to get this hat (i.e. at the time that the hat was earned, one user had 16 or more hats, and two other users had enough hats that the first user didn

最佳答案

想到的选项很少。

  1. 撇号可能会结束您的 SQL 语句。您将需要对其进行转义。

  2. 您尝试存储数据的字段太小。

关于javascript - post方法不发送全文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34685855/

相关文章:

javascript - 监听鼠标事件……除了 div 的溢出 :scroll scrollbar?

javascript - 图像多个区域的翻转效果

javascript - 向空人力车图表添加数据

javascript - 加载所有背景图像时显示页面

javascript - 显示隐藏的 div 并关闭其他的,因此一次显示 1

javascript - 可拖动元素上的 z-index 堆叠问题(jQuery UI)

php - 为什么这个模式函数返回 null?

php - 从sql server日期时间中获取日期

php - 如果使用三元运算符,如何修复我的 PHP 内联?

javascript - 使用 html 和 css 创建树