博客
关于我
在 selenium IDE 插件中添加上传云端平台的功能
阅读量:279 次
发布时间:2019-03-01

本文共 2135 字,大约阅读时间需要 7 分钟。

          /** 
* 原生 JavaScript 的 Ajax 函数
* @type { {get: Ajax.get, post: Ajax.post}}
*/
const Ajax = {
get: function(url, fn) {
// 使用 XMLHttpRequest 对象进行数据交互
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onreadystatechange = function() {
// 当请求完成时处理回应
if ((xhr.readyState == 4 && xhr.status == 200) || xhr.status == 304) {
fn.call(this, xhr.responseText);
}
};
xhr.send();
},
post: function(url, data, fn) {
// 使用 XMLHttpRequest 发送 POST 请求
var xhr = new XMLHttpRequest();
xhr.open('POST', url, true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onreadystatechange = function() {
// 处理服务器返回的响应
if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 304)) {
fn.call(this, xhr.responseText);
}
};
xhr.send(data);
}
};
export function uploadProject(_project) {
// 将项目对象转换为 JSON 格式
const project = _project.toJS();
const sideJson = JSON.stringify(project);
ModalState.showAlert({
title: '上传云端',
description: sideJson,
confirmLabel: '确定',
cancelLabel: '取消'
}, choseUpload => {
if (choseUpload) {
// 服务器地址配置(示例)
const host = 'https://localhost:9000';
const token = uuidv4();
const data = {
name: project.name,
sideJson: sideJson,
token: token
};
// 发送 POST 请求
Ajax.post(`${host}/uitestcase/upload.api`, JSON.stringify(data), res => {
console.log(res);
});
}
});
}

转载地址:http://nsea.baihongyu.com/

你可能感兴趣的文章
mysql 取表中分组之后最新一条数据 分组最新数据 分组取最新数据 分组数据 获取每个分类的最新数据
查看>>
mysql 四种存储引擎
查看>>
MySQL 基础模块的面试题总结
查看>>
MySQL 备份 Xtrabackup
查看>>
mysql 多个表关联查询查询时间长的问题
查看>>
mySQL 多个表求多个count
查看>>
mysql 多字段删除重复数据,保留最小id数据
查看>>
MySQL 多表联合查询:UNION 和 JOIN 分析
查看>>
MySQL 大数据量快速插入方法和语句优化
查看>>
mysql 如何给SQL添加索引
查看>>
mysql 字段区分大小写
查看>>
mysql 字段合并问题(group_concat)
查看>>
mysql 字段类型类型
查看>>
MySQL 字符串截取函数,字段截取,字符串截取
查看>>
MySQL 存储引擎
查看>>
mysql 存储过程 注入_mysql 视图 事务 存储过程 SQL注入
查看>>
MySQL 存储过程参数:in、out、inout
查看>>
mysql 存储过程每隔一段时间执行一次
查看>>
mysql 存在update不存在insert
查看>>
Mysql 学习总结(86)—— Mysql 的 JSON 数据类型正确使用姿势
查看>>