Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
ZheShangBank_TaoQuan_20240612
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
SparkProjects
ZheShangBank_TaoQuan_20240612
Commits
31be7dbd
Commit
31be7dbd
authored
Aug 20, 2024
by
haiyoucuv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
整理一下代码1
parent
3c07a5e8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
6 deletions
+8
-6
ajax.ts
assets/Scripts/Utils/WebNet/web/ajax.ts
+8
-6
No files found.
assets/Scripts/Utils/WebNet/web/ajax.ts
View file @
31be7dbd
/**
/**
* 到时放到Loader里,增加open类型、headers、参数、等等
* 到时放到Loader里,增加open类型、headers、参数、等等
* @param options
* @param options
*/
*/
export
function
ajax
(
options
:
ajaxParameterInt
)
{
export
function
ajax
(
options
:
ajaxParameterInt
)
{
/**
/**
...
@@ -18,7 +18,6 @@ export function ajax(options: ajaxParameterInt) {
...
@@ -18,7 +18,6 @@ export function ajax(options: ajaxParameterInt) {
/**
/**
* 对需要传入的参数的处理
* 对需要传入的参数的处理
*/
*/
var
params
=
getParams
(
options
.
data
);
var
xhr
:
XMLHttpRequest
;
var
xhr
:
XMLHttpRequest
;
/**
/**
* 创建一个 ajax请求
* 创建一个 ajax请求
...
@@ -60,6 +59,7 @@ export function ajax(options: ajaxParameterInt) {
...
@@ -60,6 +59,7 @@ export function ajax(options: ajaxParameterInt) {
// };
// };
if
(
options
.
type
==
'GET'
)
{
if
(
options
.
type
==
'GET'
)
{
const
params
=
getParams
(
options
.
data
);
xhr
.
open
(
"GET"
,
options
.
url
+
'?'
+
params
,
options
.
async
);
xhr
.
open
(
"GET"
,
options
.
url
+
'?'
+
params
,
options
.
async
);
//get请求也会需要设置请求头的情况
//get请求也会需要设置请求头的情况
if
(
options
.
headers
)
{
if
(
options
.
headers
)
{
...
@@ -83,8 +83,9 @@ export function ajax(options: ajaxParameterInt) {
...
@@ -83,8 +83,9 @@ export function ajax(options: ajaxParameterInt) {
}
}
}
}
if
(
options
.
headers
[
"Content-Type"
]
==
"application/json"
){
let
params
=
getParams
(
options
.
data
);
params
=
JSON
.
stringify
(
params
);
if
(
options
.
headers
[
"Content-Type"
]
==
"application/json"
)
{
params
=
JSON
.
stringify
(
options
.
data
);
}
}
/**
/**
...
@@ -96,8 +97,8 @@ export function ajax(options: ajaxParameterInt) {
...
@@ -96,8 +97,8 @@ export function ajax(options: ajaxParameterInt) {
/**
/**
* jsonp模拟,不考虑回调
* jsonp模拟,不考虑回调
* @param url
* @param url
* @param params
* @param params
*/
*/
export
function
jsonp
(
url
:
string
,
params
:
any
)
{
export
function
jsonp
(
url
:
string
,
params
:
any
)
{
const
src
=
url
+
'?'
+
getParams
(
params
);
const
src
=
url
+
'?'
+
getParams
(
params
);
...
@@ -128,6 +129,7 @@ function getParams(data): string {
...
@@ -128,6 +129,7 @@ function getParams(data): string {
arr
.
push
(
'_='
+
Date
.
now
());
arr
.
push
(
'_='
+
Date
.
now
());
return
arr
.
join
(
'&'
);
return
arr
.
join
(
'&'
);
}
}
//基本没用到过cache,先不加
//基本没用到过cache,先不加
interface
ajaxParameterInt
{
interface
ajaxParameterInt
{
url
:
string
,
url
:
string
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment