使<img src=""/>槽Ajax的马车PARAM

时间:2019-01-31 11:21:19

标签: javascript php jquery ajax

我使用jquery建立了一个简单的网络聊天,然后实现了图标添加器,问题是,当我通过Ajax传递输入时,带有图标的文本有时会添加图像,有时却不会,例如,如果发送只能使用图标,但是例如,如果我写文本并提供空格,它将不再显示。

我使用contenteditable =“” div作为文本,然后通过js变量即时读取它,直到我尝试传递参数为止,一切都很好

$( "#send" ).click(function() {
    var mensagem = document.getElementById("inputx").innerHTML;
    //var mensagem = mensagem.replace(/[^a-z0-9\s]/gi, '').replace(/[_\s]/g, '-')
    var username = "<?php echo $_SESSION['username'] ?>";
    $.ajax({
            type: 'POST',
            url: 'scripts/insert_chat.php',
            data:'username='+username+'&mensagem='+mensagem,
            success: function(){
                // handle response here.
                // you can still access the open variable here!
            }
    });
});

这是insert_chat.php:

<?php
require_once("../configs/database.php");
$connect = new mysqli($config['database']['host'],$config['database']['user'],$config['database']['pass'],$config['database']['db']);  
global $connect;

$mensagem =  $_POST['mensagem'];
$url = "http://milestone.gm-tests.xyz";
/*$mensagem = str_replace(array('"..','png/"'), array("..","png"), $mensagem);
$mensagem = str_replace('\"','', $mensagem);
*/
$email = $_POST['username'];

$getu = $connect->query("SELECT * FROM users WHERE email = '$email'");
$fetch = $getu->fetch_array(MYSQLI_ASSOC);
$username = $fetch['username'];
$user_id = $fetch['id'];

$insert = $connect->prepare("INSERT INTO chat
                            (username,user_id,mensagem) 
                            VALUES(?,?,?)");

$insert->bind_param("sis", $username,$user_id,$mensagem);
if($insert->execute()){ 
}else{  
    echo $connect->error; 
}

0 个答案:

没有答案