flg_debug_mode = false;
var local_cache = false;
function xmlhttp()
{
if (window.ActiveXObject) {
try {
return new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
return new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
return null;
}
}
} else if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else {
return null;
}
}
var debug = 0;
function XmlHttpConnection (_host) {
// Public Properties
this.xmlhttp = new xmlhttp();
this.async = true;
this.result = "";
this.xml = null;
this.json_object;
var formObj = this;
this.img_loading = "
"
+ ""
+ ""
// + " "
+ " | "
+ "
"
+ "
";
// Private Methods
this._createBoundary = function () {
var tmp = Math.random();
var thisDate = new Date();
tmp = Math.abs(tmp*thisDate.getTime());
tmp = "--------" + tmp + "--------";
return tmp;
}
this._createField = function (_field, _value) {
var tmp = "--" + this._boundary + this.CRLF;
if (chk_browser("MSIE") == false)
_value = _value.ReplaceAll("\n", chr(13) + chr(10));
tmp += "Content-Disposition: form-data; name=\"" + _field + "\"" + this.CRLF;
tmp += "Content-Transfer-Encoding: binary" + this.CRLF + this.CRLF;
tmp += _value + this.CRLF;
tmp += "--" + this._boundary + this.CRLF;
return tmp;
}
this.xmlhttp.onreadystatechange = function () {
if (formObj.xmlhttp.readyState == 4) {
if (formObj.xmlhttp.status == 200) {
formObj.result = formObj.xmlhttp.responseText;
}
else {
formObj.errCode = formObj.xmlhttp.status;
formObj.result = formObj.xmlhttp.responseText;
alert("Error in request!! HTTP RESPONSE STATUS: " + formObj.errCode);
}
}
}
// Private Properties
this._boundary = this._createBoundary();
this._host = _host;
this._fields = new Array();
this.CRLF = "\n";
// Public Methods
this.addField = function (_field, _value) {
this._fields.push(new Array(_field, _value));
}
this.removeField = function (_field) {
for (var i=0; i"
+ ""
+ ""
+ " "
+ " | "
+ "
"
+ "";
$j("[id='" + options.imgId + "']").empty().append(img_loading);
}
var json_data = "{\"AJAX_ASYNC_X\" : \"1\""
var e = element_list.split(",");
for (var i = 0; i< e.length; i++)
{
json_data += ",\"" + e[i] + "\": \"" + get_element_value(e[i]) + "\"" ;
}
json_data += "}";
var t, obj_data;
if (/msie/.test(navigator.userAgent.toLowerCase()) && getInternetExplorerVersion() != -1 && getInternetExplorerVersion() <= 9)
{
t = json_data.ReplaceAll('\r\n', '');
obj_data = $j.parseJSON(t);
}
else
{
t = json_data.ReplaceAll('\n', '');
obj_data = eval('(' + t + ')')
}
// var obj_data = eval('(' + t + ')')
//var obj_data = $j.parseJSON(t);
var obj = this;
$j.ajax({
url: str_url,
type : "POST",
dataType: "html",
data: obj_data,
success: function(data) {
if ( options.imgId !="")
$j("[id='" + options.imgId + "']").empty();
obj.result = data;
try
{
obj.json_object = obj.return_object();
}
catch (e)
{
str_error_msg = "XmlHttpConnection.get_object() error: Can't get json object !!"
+ "\n Error Message:" + e.Message
+ "\n result = " + obj.result;
display_error(str_error_msg);
return (false);
}
try
{
if (obj.json_object.flg_error == 1)
obj.json_object.on_error();
else
obj.json_object.on_success();
}
catch (e)
{
}
async_function(obj.json_object);
},
error : function (XMLHttpRequest, textStatus, errorThrown) {
var msg = "";
try {
msg = "
" + XMLHttpRequest.responseText;
} catch (ex) {}
jalert("System Error:" + textStatus + msg);
}
})
}
this.get_object = function (PageName, field_list, options)
{
this.xmlhttp = new xmlhttp();
this._fields = new Array();
this.async = false;
this._host = PageName;
var _field = field_list.split(",");
if (field_list != "") {
for (var i = 0; i < _field.length; i++)
{
if (PageName.indexOf("ajax_data_search") > 0)
formObj.addField(_field[i], get_element_value(_field[i]).ReplaceAll("'", "''") );
else
formObj.addField(_field[i], get_element_value(_field[i]) );
}
}
if (this._before_connect() == false)
return (false);
if (typeof(options != "undefined"))
if (options == true) local_cache = true;
this.send();
//alert(this.xmlhttp.readyState + " " + this.xmlhttp.status);
if (this.xmlhttp.readyState == 4)
{
if (this.xmlhttp.status == 200)
{
this.result = this.xmlhttp.responseText;
try
{
this.json_object = this.return_object();
}
catch (e)
{
str_error_msg = "XmlHttpConnection.get_object() error: Can't get json object !!"
+ "\n Error Message:" + e.Message
+ "\n result = " + this.result;
display_error(str_error_msg);
return (false);
}
try
{
if (this.json_object.flg_error == 1)
this.json_object.on_error();
else
this.json_object.on_success();
}
catch (e)
{
}
}
else
this._recieve_error();
this._after_connect();
//alert("XmlHttpConnection.get_object() receive data ..!!");
return (this.json_object);
}
return (null);
}
this.get_xml = function (PageName, field_list)
{
this.xmlhttp = new xmlhttp();
this._fields = new Array();
this.xmlDom = createXMLDom();
this.async = false;
this._host = PageName;
var _field = field_list.split(",");
for (var i = 0; i < _field.length; i++)
formObj.addField(_field[i], get_element_value(_field[i]) );
if (this._before_connect() == false)
return (false);
this.send();
//alert(this.xmlhttp.readyState + " " + this.xmlhttp.status);
if (this.xmlhttp.readyState == 4)
{
if (this.xmlhttp.status == 200)
{
this.result = this.xmlhttp.responseText;
this.xmlDom = this.xmlhttp.responseXML
return (this.xmlDom);
}
else
this._recieve_error();
this._after_connect();
//alert("XmlHttpConnection.get_object() receive data ..!!");
return (null);
}
return (null);
}
}
function display_error(str)
{
if (flg_debug_mode == true)
{
var reply = prompt("AJAX執行時期發現錯誤!是否要將錯誤訊息顯示到畫面上,請輸入欲顯示的物件名稱!", "txt.debug.source");
if (reply != null)
{
try { show("display.debug.source"); } catch (e) {}
try { set_element_value(reply, str); return (false); } catch (e) {}
try { $(reply).innerHTML = str; return (false); } catch (e) {}
}
else
window.status = str;
}
}
function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
var rv = -1; // Return value assumes failure.
if (navigator.appName == 'Microsoft Internet Explorer')
{
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat( RegExp.$1 );
}
return rv;
}