$.support.cors = true; /** * url: 特定功能的Url,如:/Login_webSdkAuth.action * callback: 回调函数 * requestType: The type of request * to make ("POST" or "GET"), default is "POST". * requestJson: 请求参数 */ function chatRequest(url, requestType, requestJson, callback) { if (requestType == null) requestType = "POST"; var headers; var contentType; var requestData; if (requestType == "POST" || requestType == "PUT"){ contentType = "application/json;charset=UTF-8"; requestData = JSON.stringify(requestJson); } else { requestData = requestJson; } var headerJson = {}; if (getServerKey()){ headerJson.serverKey = getServerKey(); } if (getApiKey()){ headerJson.apiKey = getApiKey(); } console.log(callback) if (callback) { // async call $.ajax({ url : _urlHeadAjax + url, async : true, crossDomain: true, type : requestType, data : requestData, headers: headerJson, cache: false, contentType : contentType, success : function(responseJson) { console.log(responseJson) callback(responseJson); //showResult(0, responseJson, url + ":"); }, error : function(responseJson) { //showResult(0, responseJson.responseText, url + " Err:"); } }); } else { // sync call var rst; $.ajax({ url : _urlHeadAjax + url, async : false, crossDomain: true, type : requestType, data : requestData, headers: headerJson, cache: false, contentType : contentType, success : function(responseJson) { console.log(responseJson) rst = responseJson; //showResult(0, responseJson, url + ":"); }, error : function(responseJson) { //showResult(0, responseJson.responseText, url + " Err:"); } }); return rst; } } function getServerKey(){ return sessionStorage.getItem("serverKey"); } function getApiKey(){ return sessionStorage.getItem("apiKey");; } function AirSession() { this.sessionId = ""; this.sessionIndex = 0; this.sessionState = SESSION_STATE_IDLE; this.mediaState = MEDIA_STATE_IDLE; this.mediaSpeaker = null; this.lock = 0; }