Commit cc11e77d authored by 王勇霞's avatar 王勇霞

xhr.send

parent bd582a83
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>21天"云"健身</title> <title>21天“云”健身</title>
<meta name="viewport" <meta name="viewport"
content="width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no" /> content="width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" /> <meta name="apple-mobile-web-app-capable" content="yes" />
......
...@@ -76,7 +76,9 @@ export function ajax(options: ajaxParameterInt) { ...@@ -76,7 +76,9 @@ export function ajax(options: ajaxParameterInt) {
/** /**
* POST请求设置请求头 * POST请求设置请求头
*/ */
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); // xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.setRequestHeader('Accept', 'application/json, text/plain, */*');
xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
if (options.headers) { if (options.headers) {
for (let key in options.headers) { for (let key in options.headers) {
xhr.setRequestHeader(key, options.headers[key]); xhr.setRequestHeader(key, options.headers[key]);
...@@ -85,7 +87,7 @@ export function ajax(options: ajaxParameterInt) { ...@@ -85,7 +87,7 @@ export function ajax(options: ajaxParameterInt) {
/** /**
* 发送请求参数 * 发送请求参数
*/ */
xhr.send(params); xhr.send(JSON.stringify(options.data));
} }
} }
......
...@@ -10,11 +10,7 @@ let urlParams: { [key: string]: string | true }; ...@@ -10,11 +10,7 @@ let urlParams: { [key: string]: string | true };
export function getUrlParams(key: string, refreshCache: boolean = false): string | true { export function getUrlParams(key: string, refreshCache: boolean = false): string | true {
if (urlParams && !refreshCache) return urlParams[key]; if (urlParams && !refreshCache) return urlParams[key];
urlParams = {}; urlParams = {};
let search = window.location.search; let search = '?' + window.location.href.split("?")[1]
try {
search = top.location.search; //尝试获取顶层的链接
} catch (e) {
}
//获取链接参数 //获取链接参数
for (let item of search.replace('?', '').split('&')) { for (let item of search.replace('?', '').split('&')) {
let arr = item.split('='); let arr = item.split('=');
......
This diff is collapsed.
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
"@babel/core": "^7.14.6", "@babel/core": "^7.14.6",
"@babel/preset-env": "^7.14.7", "@babel/preset-env": "^7.14.7",
"ali-oss": "^4.11.4", "ali-oss": "^4.11.4",
"canvas": "^2.11.0",
"chalk": "^2.3.0", "chalk": "^2.3.0",
"co": "^4.6.0", "co": "^4.6.0",
"del": "^2.2.1", "del": "^2.2.1",
......
This diff is collapsed.
This diff is collapsed.
...@@ -4,11 +4,6 @@ import { GDispatcher } from "./Main"; ...@@ -4,11 +4,6 @@ import { GDispatcher } from "./Main";
import { getUrlParams } from "../module/web/webTools"; import { getUrlParams } from "../module/web/webTools";
import { isFromShare, newUser } from 'duiba-utils'; import { isFromShare, newUser } from 'duiba-utils';
let mergeData = {
user_type: newUser ? '0' : '1',
is_from_share: isFromShare ? '0' : '1',
}
//////////////星速台接口方法集成 //////////////星速台接口方法集成
/** /**
* web接口枚举,mock 文件名类似aaa/homeInfo.do * web接口枚举,mock 文件名类似aaa/homeInfo.do
...@@ -79,7 +74,7 @@ export function sendWebNet( ...@@ -79,7 +74,7 @@ export function sendWebNet(
headers?: any, headers?: any,
): Promise<dataOut> { ): Promise<dataOut> {
//处理下参数 //处理下参数
parameter = { ...parameter, ...mergeData }; parameter = { ...parameter };
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
...@@ -123,11 +118,11 @@ export function sendWebNet( ...@@ -123,11 +118,11 @@ export function sendWebNet(
//网络请求 //网络请求
ajax({ ajax({
url: netName.replace("{projectId}", getProjectId()), //请求地址 url: netName, //请求地址
type: isGet ? 'GET' : "POST", //请求方式 type: isGet ? 'GET' : "POST", //请求方式
data: parameter || {}, //请求参数 data: parameter || {}, //请求参数
dataType: "json", // 返回值类型的设定,暂时只有json dataType: "json",// 返回值类型的设定,暂时只有json
async: true, //是否异步 async: true,//是否异步
headers: headers, headers: headers,
success: function (response) { success: function (response) {
//发现有些接口成功了,但是response为空 //发现有些接口成功了,但是response为空
...@@ -154,7 +149,7 @@ export function sendWebNet( ...@@ -154,7 +149,7 @@ export function sendWebNet(
); );
}, },
error: function (status) { error: function (status) {
if (!hideMsg) showToast("网络超时"); if (!hideMsg) showToast("网络开小差了, 请稍后再试");
callback && callback(false) callback && callback(false)
resolve({ success: false }); resolve({ success: false });
console.log("接口" + netName + ":网络超时"); console.log("接口" + netName + ":网络超时");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment