Commit 31be7dbd authored by haiyoucuv's avatar haiyoucuv

整理一下代码1

parent 3c07a5e8
/**
* 到时放到Loader里,增加open类型、headers、参数、等等
* @param options
* @param options
*/
export function ajax(options: ajaxParameterInt) {
/**
......@@ -18,7 +18,6 @@ export function ajax(options: ajaxParameterInt) {
/**
* 对需要传入的参数的处理
*/
var params = getParams(options.data);
var xhr: XMLHttpRequest;
/**
* 创建一个 ajax请求
......@@ -60,6 +59,7 @@ export function ajax(options: ajaxParameterInt) {
// };
if (options.type == 'GET') {
const params = getParams(options.data);
xhr.open("GET", options.url + '?' + params, options.async);
//get请求也会需要设置请求头的情况
if (options.headers) {
......@@ -83,8 +83,9 @@ export function ajax(options: ajaxParameterInt) {
}
}
if(options.headers["Content-Type"] == "application/json"){
params = JSON.stringify(params);
let params = getParams(options.data);
if (options.headers["Content-Type"] == "application/json") {
params = JSON.stringify(options.data);
}
/**
......@@ -96,8 +97,8 @@ export function ajax(options: ajaxParameterInt) {
/**
* jsonp模拟,不考虑回调
* @param url
* @param params
* @param url
* @param params
*/
export function jsonp(url: string, params: any) {
const src = url + '?' + getParams(params);
......@@ -128,6 +129,7 @@ function getParams(data): string {
arr.push('_=' + Date.now());
return arr.join('&');
}
//基本没用到过cache,先不加
interface ajaxParameterInt {
url: string,
......
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