-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest.js
More file actions
53 lines (53 loc) · 1.54 KB
/
request.js
File metadata and controls
53 lines (53 loc) · 1.54 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
//-----------------------------------------------------------------
(function(){
var _token="";
VmAPI.set_token=function(token){
_token=token;
};
VmAPI.request=function(options){
VmAPI.request(_token,options)
};
VmAPI.tttt=function(){
return _token;
};
}());
VmAPI._request=function(token,options){
var data=options.data;
var call_back=options.call_back;
VmFramework.ajax_server_error=0;
var url=VmFramework.api_base+'api.aspx';
$.ajax({
type: "POST",
url: url,
contentType: "application/json",
charset:"utf-8",
dataType: "json",
error: function(jqXHR,error, errorThrown){ if(jqXHR.status) {alert(jqXHR.responseText);} else {alert("Something went wrong");}},
data: JSON.stringify(data),
success: function(c,textStatus, request){
if(VmFramework.ajax_server_error==1) return;
try{
if(call_back!==undefined) call_back(c);
}catch(err){
alert(err.toString());
}
},
dataFilter: VmAPI.request_filter,
beforeSend:function(jqXHR,settings){
jqXHR.setRequestHeader('Authorization', token);
},
})
};
//-----------------------------------------------------------------
VmAPI.request_filter=function(c){
var a=$.parseJSON(c);
if(a.Error!=undefined){
alert("Server side error: "+a.Error);
VmFramework.ajax_server_error=1;
if(typeof(VmFramework.submit_div)!=='undefined' && VmFramework.submit_div!=""){
$('#D'+VmFramework.submit_div).triggerHandler('submit_failed');
}
}
return c;
}
//-----------------------------------------------------------------