ajax - 操作“成功”数据会破坏递归 ajax
问题描述
我正在编写一个自动脚本来执行爬网作业。我将 ajax 函数放在递归函数中以自动化该过程。ajax 函数不断从列表数组中获取 URL,这一切都有效。但是,在我输入此代码后它停止工作:$("#myframe").html(temp.body);
,temp
“成功”数据在哪里,并且temp.body
是 json 响应的一部分。然后,代码停在列表的第二项。请帮我处理递归ajax的数据操作。谢谢你。
var idlist = ["10001","10002","10003"];
var index = 0;
function job(id) {
$.get("https://cors-proxy.htmldriven.com/?url=http://www.olgame.tw/sds/robot_detail.php?id="+id, function( temp ) {
$("body").append('<div id="myframe"></div>');
$("#myframe").html(temp.body); //This line causes problem. The entire code stops at here.
$("div#myframe").remove();
if (idlist[index+1] != undefined) {
index++;
job(idlist[index]);
} //index stops at '1'.
});
}
job(idlist[index]);
完整的代码在这里。
解决方案
在开始任何“数据操作”之前,应首先删除响应中的任何脚本,以防止可能的 ajax 错误。
var cont = temp.body.replace(/<script.*?<\/script>/g,'');
$("#myframe").html(cont);
推荐阅读
- python - Flask Flatpages:如何在降价文件中添加(和显示)表情符号?
- python - 如何在heroku上使用pyodbc部署python dash应用程序
- asp.net-mvc - 上传种子数据时出错?
- selenium-webdriver - selenium chromedriver 和 chrome 二进制即使它们匹配版本也不会连接
- python - 为什么我在 vscode 中使用 pygame 而在 pycharm 中没有出现错误?
- python-3.x - Tkinter - 背景部分透明
- ios - 在 Windows 上运行 .ipa 应用程序
- amazon-web-services - AWS 备份查询 (EC2/EBS)
- filter - 仅在两个表之间使用内部联接,无法过滤“正确”的数据库列
- python - 密集层无法识别输入形状,即使它应该