sta*_*ack 2 javascript php jquery
在我的项目中,我想将div内容存储到DB.内容如下:
<span>name:</span><input type="text" id="inputid" value="John"><br />
Run Code Online (Sandbox Code Playgroud)
所以我选择了innerHTML来成功获取它们.使用Ajax,内容将存储到DB.
昨天,我发现应该调用stripslashes()来格式化内容,并且可以成功更新.
但今天striplashes()没有做任何事情.这是我的js代码:
var slcId = $('#slcStNum').val();
var tmTgDvHtml=document.getElementById("timeTagDiv").innerHTML;
$.ajax({
dataType:'html',
type:"POST",
url:"get_ajax_csc_div.php",
data:{htmlCnt:tmTgDvHtml,slcId:slcId},
success:function (data)
{
alert("test");
}
});
Run Code Online (Sandbox Code Playgroud)
这是html代码:
<div id="timeTagDiv"><span>name:</span><input type="text" id="inputid" value="John"><br /></div>
Run Code Online (Sandbox Code Playgroud)
这是get_ajax_csc_div.php代码
<?php
if(isset($_POST['htmlCnt']))
{
include("DB.php");
$htcnt=stripslashes(".$_POST['htmlCnt'].");
$sql="update IDC SET stprocess='$htcnt' where id='".$_POST['slcId']."';";
$sel = $conn->exec($sql);
}
?>
Run Code Online (Sandbox Code Playgroud)
我将dataType:'html'更改为dataType:'json',但它再次失败.谁能帮我?
这是因为你的_POST[]超全局被引号括起来,使它成为一个字符串.
改变这个
$htcnt = stripslashes(".$_POST['htmlCnt'].");
Run Code Online (Sandbox Code Playgroud)
有了这个
$htcnt = stripslashes($_POST['htmlCnt']);
Run Code Online (Sandbox Code Playgroud)