Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TYSCRIPT = TYSCRIPT.extend({
- get: function(url, data, callback, type) {
- // shift arguments if data argument was omited
- if (TYSCRIPT.isFunction(data))
- {
- type = type || callback;
- callback = data;
- data = null;
- }
- return TYSCRIPT.ajax({
- type: "GET",
- url: url,
- data: data,
- success: callback,
- dataType: type
- });
- },
- getScript: function(url, callback) {
- return TYSCRIPT.get(url, null, callback, "script");
- },
- getJSON: function(url, data, callback) {
- return TYSCRIPT.get(url, data, callback, "json");
- },
- getXML: function(url, data, callback) {
- return TYSCRIPT.get(url, data, callback, "xml");
- },
- post: function(url, data, callback, type) {
- // shift arguments if data argument was omited
- if (TYSCRIPT.isFunction(data))
- {
- type = type || callback;
- callback = data;
- data = {};
- }
- return TYSCRIPT.ajax({
- type: "POST",
- url: url,
- data: data,
- success: callback,
- dataType: type
- });
- },
- ajaxSetup: function(settings)
- {
- TYSCRIPT.extend(TYSCRIPT.ajaxSettings, settings);
- },
- ajaxSettings: {
- url: '',
- global: true,
- type: "GET",
- contentType: "application/x-www-form-urlencoded",
- processData: true,
- async: true,
- /*
- timeout: 0,
- data: null,
- username: null,
- password: null,
- traditional: false,
- */
- // This function can be overriden by calling TYSCRIPT.ajaxSetup
- xhr: function()
- {
- try
- {
- return new ActiveXObject("Microsoft.XMLHTTP");
- }
- catch(e)
- {
- return new ActiveXObject("Msxml2.XMLHTTP");
- }
- },
- accepts: {
- xml: "application/xml, text/xml",
- html: "text/html",
- script: "text/javascript, application/javascript",
- json: "application/json, text/javascript",
- text: "text/plain",
- _default: "*/*"
- }
- },
- ajax: function(origSettings)
- {
- var s = TYSCRIPT.extend(true, {}, TYSCRIPT.ajaxSettings, origSettings),
- status, data, type = s.type.toUpperCase();
- Interop.Call("wininet.dll", "DeleteUrlCacheEntryW", s.url); //clear cache
- s.url = s.url.replace(/#.*$/, "");
- var xhr = s.xhr();
- if(!xhr)
- {
- return;
- }
- xhr.onreadystatechange = function ()
- {
- if(xhr.readyState === 4)
- {
- if(s.dataType === "json")
- {
- s.success.call(this, JSON.parse(xhr.responseText));
- }
- else if(s.dataType === "xml")
- {
- s.success.call(this, xhr.responseXML);
- }
- else
- {
- s.success.call(this, xhr.responseText);
- }
- }
- }
- if (s.username)
- {
- xhr.open(type, s.url, s.async, s.username, s.password);
- }
- else
- {
- xhr.open(type, s.url, s.async);
- }
- if (type === "POST")
- {
- xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
- xhr.setRequestHeader("Content-length", s.data.length);
- xhr.setRequestHeader("Connection", "close");
- }
- try
- {
- xhr.send(s.data === null ? null : s.data);
- }
- catch(sendError)
- {
- Debug.Trace(sendError);
- }
- return xhr;
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement