php - 如何在php中清理ajax发布数据?
问题描述
我有一个要清理的文本字段。来自文本字段的数据通过 ajax post 发送到 php 文件。在将其写入 mysql 数据库之前,我想在 php 文件中清理此字符串。
我的问题是(据我了解)我无法在该 php 文件中调用任何清理函数,因为它是由 ajax 调用的,因此这些函数不可用。这个对吗?如果是这样,您如何清理这些数据?
带有清理功能的 ajax 调用的 php 文件示例...
function sanitizeString($string)
{
$string = strip_tags($string); //I cannot access these functions because the file was called by ajax
$string = htmlentities($string);
$string = stripslashes($string);
}
$group_id = sanitizeString($_POST['userid']);
$textbox_value = sanitizeString($_POST['title_text']);
//Write these values to mysql database...
//DOES NOT WORK
$group_id = sanitizeString($_POST['userid']);
$textbox_value = sanitizeString($_POST['title_text']);
//replacing above with this does work (and commenting out function)
$group_id = $_POST['userid'];
$textbox_value = $_POST['title_text'];
解决方案
推荐阅读
- java - 覆盖和覆盖
- javascript - 如何将自动播放插入图像滑块?
- c# - 在 C# 中将 XML 文件反序列化为对象
- linux - 通过列出 bash 中的目录来构造 $PATH
- excel - 突出显示excel条形图数据表中的最大条目
- c# - 实体框架 asp.net mvc5-无法将 lambda 表达式转换为类型“字符串”,因为它不是委托类型
- amazon-web-services - API 网关授权者和注销(性能/安全注意事项)
- html - 使用 ASP.NET 将动态文本添加到 Html ActionLink 中的 ToolTip
- laravel - 使用 Socialite Laravel 向 Facebook 进行身份验证时如何打开新对话框
- openid - 使用 openId 连接身份服务器的两个实例