我有一个问题,可能有与我正在考虑做的不同的答案。
所以,我有一个由数据库填充的文本区域。我允许用户将其用作记事本之类的。
其中一些注释可能会变得相当大,并可能超出 URL 字符限制。我还必须对字符串进行编码(我正在使用encodeURIComponent),这也会减少字符数量。
我认为最好的方法是将文本区域转换为文件,然后将文件发布到我的处理程序 php 文件中,然后将其上传到数据库等中。我不确定如何使用 JQuery/Javascript 执行此操作,或者是否有其他方法来处理此问题。
提前致谢!
-- 表代码--
echo "<table class='content' id='quick-notes-list'>
<tr style='border-bottom:2pt solid #DFEFFC'>
<td colspan='2'>Note Name</td>
<td>Last Updated</td>
</tr>";
$i = 0;
while ( $Notes = mysql_fetch_array($getNotes) )
{
$style = ( $i % 2 ? 'ui-state-default row' : 'altrow row'); $i++;
$noteDate = date("M, d Y", strtotime($Notes['updated']));
$noteTime = date("g:i a", strtotime($Notes['updated']));
echo "
<tr class='noteName' onMouseOver=\"this.className='ui-widget-header row'\" onMouseOut=\"this.className='$style'\" >
<td valign='top'>
<a href='{$Notes['note_id']}'></a>
<b>{$Notes['note_name']}</b>
<br />
<i id='summary{$Notes['note_id']}'>" . substr($Notes['note_body'], 0, 150) . "...</i>
</td>
<td width='160' valign='top'>" . str_replace(" ", " ", $Contact['name']) . "</td>
<td width='120' valign='top'>
<i>" . str_replace(" ", " ", " {$noteDate} - {$noteTime}") . "</i>
</td>
</tr>
<tr id='note{$Notes['note_id']}' style='display: none' onMouseOver=\"this.className='ui-widget-header row'\" onMouseOut=\"this.className='$style'\">
<td colspan='2'>
<textarea id='note-body-{$Notes['note_id']}'>{$Notes['note_body']}</textarea>
</td>
<td style='text-align: right;'>
<button id='saveNote' value='{$Notes['note_id']}' class='ui-state-focus'>Save</button>
<button id='deleteNote' value='{$Notes['note_id']}' class='ui-state-focus'>Delete</button>
</td>
</tr>
";
}
-- 下面的 AJAX 函数 --
$('#saveNote').click(function() {
noteID = $(this).attr('value');
newText = encodeURIComponent($('#note-body-' + noteID).val());
$.ajax({
url : "manage-save-quick-notes.php",
type : "POST",
data : data,
success: function(data, textStatus, jqXHR)
{
//data - response from server
},
error: function (jqXHR, textStatus, errorThrown)
{
}
});
最佳答案
- 在不需要的地方上传文件可能不是一个好主意。这只是一个安全问题
- 如果您通过 POST 请求发送数据,则大小实际上不会成为问题,因为它的限制是在您的 Apache 配置中在服务器端设置的。
要增加 POST 大小限制: Increasing the maximum post size
关于javascript - 将文本区域转换为文件 (HTML JQuery AJAX PHP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41622208/