<,./;'[]=-|\ 在 php 中使用 AJAX 调用。但是在数据库中它保存为: ~`@#$%^???? 这是我的 AJAX 调-6ren">
gpt4 book ai didi

php - 如何将字符串保存在mysql数据库中

转载 作者:行者123 更新时间:2023-11-30 18:41:56 24 4
gpt4 key购买 nike

我正在尝试保存这个字符串:

~`@#$%^&*()_+}{":?><,./;'[]=-|\ 

在 php 中使用 AJAX 调用。但是在数据库中它保存为:

~`@#$%^????

这是我的 AJAX 调用

function saveComment(timesheetId,activityId,date,comment,employeeId) {

var r = $.ajax({
type: 'POST',
url: commentlink,
data: "timesheetId="+timesheetId+"&activityId="+activityId+"&date="+date+"&comment="+comment+"&employeeId="+employeeId,
async: false
}).responseText;

return r;
}

编辑:修复了字符串和代码的显示。

最佳答案

您需要在 javascript 中调用 encodeURIComponent在将其发送到服务器之前在带有奇怪字符的字符串上。

编辑:Tomalak 指出了一个更好的方法。

关于php - 如何将字符串保存在mysql数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6611933/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com