cross.js
1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* 跨域发送信息工具库
*/
var config = require('./config');
var yasPath = config.yasPath;
var yasImgDomain = config.yasImgDomain;
//发送图片方式
exports.imgSend = function (param, callback)
{
var image = new Image(1, 1);
image.src = yasImgDomain+yasPath+'ya.gif?'+param;
image.onload = function()
{
image.onload = null;
if(callback)
{
callback();
}
};
};
// ajax方式
// 需要服务端设置 Access-Control-Allow-Origin *,Access-Control-Allow-Credentials = true,
exports.ajaxSend = function (param, callback)
{
var request,Request = window.XDomainRequest;
if(Request)
{
request = new Request();
request.open("POST", yasPath);
}
else
{
if(window.XMLHttpRequest)
{
request = new window.XMLHttpRequest();
}
else
{
Request = new window.ActiveXObject("Microsoft.XMLHTTP");
}
request.open("POST", yasPath, _true);
request.setRequestHeader("Content-Type", "text/plain");
}
if(request)
{
request.onreadystatechange = function()
{
if(request.readyState == 4)
{
if(callback)
{
callback();
}
request = null;
}
};
request.send(param);
return true;
}
return false;
};