Javascript 第二个ajax函数在调用时不触发
我有两个AJAX函数,一个链接到编辑MYSQL表的文件,另一个将新内容加载到Javascript 第二个ajax函数在调用时不触发,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我有两个AJAX函数,一个链接到编辑MYSQL表的文件,另一个将新内容加载到 加载新数据的函数未启动 此函数链接到一个名为clear_tasks.php的页面,该页面将截断数据库中的一个表 function clear_tasks(){ var xmlhttp; if( window.XMLHttpRequest ){ xmlhttp = new XMLHttpRequest(); } else { xmlhttp = new ActiveXObje
加载新数据的函数未启动
此函数链接到一个名为
clear_tasks.php
的页面,该页面将截断数据库中的一个表
function clear_tasks(){
var xmlhttp;
if( window.XMLHttpRequest ){
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject( 'Microsoft.XMLHTTP' );
}
xmlhttp.open('GET', 'script_files/clear_tasks.php', true);
xmlhttp.send();
}
下一个函数链接到一个名为task_info.php
的页面,该页面包含所有表项的列表
function load_content_from_file( div_id, url ){
var xmlhttp;
if( window.XMLHttpRequest ){
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject( 'Microsoft.XMLHTTP' );
}
xmlhttp.onreadystatechange = function(){
if( xmlhttp.readyState == 4 && xmlhttp.status == 200 ){
document.getElementById(div_id).innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open('GET', url, true);
xmlhttp.send();
}
触发这些事件的
如下所示:
<div onClick="clear_tasks(); load_content_from_file('task_list', 'script_files/task_info.php');">Clear Tasks</div>
清除任务
load\u content\u from_file()
函数使用两个参数:div\u id
它是从task\u info.php
加载内容的div,当然是源文件本身(task\u info.php
)
load\u content\u from\u file()
函数未启动,我必须刷新页面以查看新内容(我在$(document.ready()
函数中使用load\u content\u from\u file()
)
为什么load\u content\u from\u file()
函数没有启动?我试过使用setInterval()
和setTimeout()
函数,但没有用。我自己检查了你的代码。这两个函数都是'fired clear_tasks()'
和'load_content_from_file'
在我单击“clear tasks”时启动
问题可能出现在'script\u files/task\u info.php'
路径上,或者在task\u info.php
中,它应该响应“task\u list”div的数据
因为如果我通过“task\u info.php”返回简单文本,那么文本将顺利地追加到“task\u list”div中。我认为这与从\u file()加载内容后发生的数据库插入过程有关。
函数。