我是用ASP部署的。奇怪的是from submit提交的时侯保存到SQL没有问题,用jquery ajax提交就有问题。两种结果如下:
from submit提交:<img src="/upfiles/image/20141011/20141011130077537753.gif" alt=""/>
jquery ajax提交:<imgsrc="/upfiles/image/20141011/20141011130077537753.gif"alt=""/>
空格全被自动消掉了。
html:
<form name="example" method="post" action="?Action=Save">
<textarea id="content" name="content" style="height:300px; padding:10px;width:500px;overflow:auto" >
<%=htmlspecialchars(content)%>
</textarea>
<input type="button" id="svaeBtn" name="svaeBtn" onclick="saveSms()" value="提交" />
</form>
//初始化编辑器
var option = {
cssPath : 'plugin/kindeditor/plugins/code/prettify.css',
uploadJson : 'plugin/kindeditor/asp/upload_json.asp',
fileManagerJson : 'plugin/kindeditor/asp/file_manager_json.asp',
allowFileManager : true,
items:['image'],
langType:"zh_CN",
afterBlur: function () { this.sync(); }
}
KindEditor.ready(function(K) {
var editor1 = K.create('textarea[name="content"]',option);
});
异步:
function saveSms(){
var $content = $("#content");
var $smsid = $("#smsid");
var content = $.trim($content.val());
var id = $.trim($smsid.val());
//alert(content) 此处结果:<img src="/upfiles/image/20141011/20141011130077537753.gif" alt="" />
var param = "content="+content;
param += "&id="+id;
$.ajax({
url: "?Action=Save",
type: "POST",
processData: false,
data: param,
cache: false,
dataType :"json",
success: function(data){
if(data.rc==0){
alert(data.rm);
}else{
alert(data.rm);
};
}
});
}
后台处理:
sub saveSms
Dim sql,rs,str
dim content,Id
Id = Trim(Request.Form("id"))
content = htmlspecialchars(Trim(Request.Form("content")))
If inull(content) Then
rc = 21
rm = "对不起,您提交的信息不能为空!"
ResponseJson()
End If
'//如果当前用户是测试帐号
If session("user_type") = False Then
Sql="select COUNT(*) from web_sms where sms_writer='"&session("user_name")&"'"
On error Resume Next
set rs = conn.execute(Sql)
' if not inull(rs("sms_writer")) then
' rc=21
' rm = "测试帐号只能发表一条信息!"
' ResponseJson()
' end if
End If
'//没有登陆不能提交
' If inull(session("user_name")) Then
' rc=21
' rm = "请重新登陆帐号!"
' ResponseJson()
' End If
If inull(Id) Then
Sql = "INSERT INTO web_sms(sms_content,sms_addtime,sms_writer) VALUES ('"&content&"','"&now()&"','"&session("user_name")&"')"
Else
Sql = "UPDATE web_sms SET sms_content='"&content&"',sms_addtime='"&now()&"' where id="&Id
End If
On error Resume Next
conn.Execute(Sql)
If err.number =0 Then
conn.CommitTrans '如果没有conn错误,则执行事务提交
rc = 0
rm = "操作成功!"
sql = "select id from web_sms where sms_content='"&content&"'"
set rs = conn.execute(sql)
other = """id"":"& rs("id")
Else
conn.RollbackTrans '否则回滚
strerr=err.Description
rc = 21
rm = "操作失败!"
End If
ResponseJson()
rs.close
set rs=nothing
end sub
请高手帮忙看一下。感激不尽!