gpt4 book ai didi

php - 添加 ajax 自动保存后,与数据库错误的连接过多

转载 作者:行者123 更新时间:2023-11-30 22:41:34 25 4
gpt4 key购买 nike

我有 PHP 站点和 MySql 数据库我刚刚为文本区域添加了自动保存其中一位用户收到以下错误:

连接太多...无法连接到数据库

也许我必须更改我的 ajax 自动保存:

bkLib.onDomLoaded(function(){
var myEditor = new nicEditor({iconsPath : 'include/nicEdit/nicEditorIcons.gif'}).panelInstance('area1');

auto_save_func(myEditor);

});

function auto_save_func(myEditor)
{

draft_content=myEditor.instanceById('area1').getContent();

int_id='<?=$_GET[interview_id]?>';

$.post("ajax_for_auto_save_interview.php", { interview_id: int_id,content:draft_content},
function(data){ });

setTimeout( function() { auto_sav_func(myEditor); }, 100);

}

在“ajax_for_auto_save_interview.php”页面中,我包括了与数据库的连接。

最佳答案

  1. 首先,您应该在每次使用后打开 mysql 连接时关闭它。
  2. 您可以使用 javascript 变量来检查 AJAX 调用是否已发出以及是否已完成。只有完成后,您才能重新发出新的调用

像这样:

var isAjaxStarted = 0;
bkLib.onDomLoaded(function(){
var myEditor = new nicEditor({iconsPath : 'include/nicEdit/nicEditorIcons.gif'}).panelInstance('area1');

if(isAjaxStarted == 0)
auto_save_func(myEditor);

});

function auto_save_func(myEditor)
{
isAjaxStarted = 1;
draft_content=myEditor.instanceById('area1').getContent();

int_id='<?=$_GET[interview_id]?>';

$.post("ajax_for_auto_save_interview.php", { interview_id: int_id,content:draft_content},
function(data){ isAjaxStarted = 0; });

setTimeout( function() { auto_sav_func(myEditor); }, 100);

}

关于php - 添加 ajax 自动保存后,与数据库错误的连接过多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31000106/

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