// ******* Copyright 2008 by fh@etas-it.ch ******* /* // ************************************************************************************* // JSON // Version mit Reroute (XMLhttpRequest NOK --> IFRAME) // // Output: // ReturnObj // .ReturnCode // .ReturnText // &OutputObj // .&x // .&y // ************************************************************************************* */ var gJSON_cb; var gJSON_string; var gJSON_XMLhttpRequest_switch = 'y'; var gJSON_timeout; var gJSON_iframe_created = 'n'; var gJSON_IFrameObj; function JSON_rpc_json(inCallBack, inString) { // save Input gJSON_cb = inCallBack; gJSON_string = inString; if (gJSON_XMLhttpRequest_switch == 'y') { // Version mit XMLhttpRequest // alert("use XMLhttpRequest"); priv_JSON_rpc_json_XMLhttpRequest(); } else { // Version mit IFRAME // iframe mit dieser ID muss irgendwoe im HTML definiert sein: // priv_JSON_rpc_json_iframe(); } } function priv_JSON_rpc_json_XMLhttpRequest() { var wDate= new Date(); var wSec = wDate.getSeconds(); var wMS = wDate.getMilliseconds(); var wTS = wSec * wMS; priv_JSON_get_HttpReq(); if (gJSON_HttpReq) { var wURI = gJSON_string + "×tamp=" + wTS; gJSON_HttpReq.open("GET", wURI, /*async*/true); gJSON_HttpReq.onreadystatechange = priv_JSON_rpc_json_callback_XMLhttpRequest; gJSON_HttpReq.send(/*no params*/null); wMilliSec = 5000; gJSON_timeout = window.setTimeout("priv_JSON_XMLhttpRequest_break()", wMilliSec); } else { // Aufruft mi IFRAME (ohne Break, da kein HttpReq-Obj vorhanden! gJSON_XMLhttpRequest_switch = 'n'; priv_JSON_rpc_json_iframe(); } } function priv_JSON_rpc_json_iframe_create( ) { if (gJSON_iframe_created == 'n') { gJSON_iframe_created = 'y'; var wIFRAME = document.createElement("IFRAME"); wIFRAME.id = "i_"; wIFRAME.src = "#"; wIFRAME.width = "0px"; wIFRAME.height = "0px"; wIFRAME.border = "0px"; document.body.appendChild(wIFRAME); } } function priv_JSON_rpc_json_iframe() { var wDate= new Date(); var wSec = wDate.getSeconds(); var wMS = wDate.getMilliseconds(); var wTS = wSec * wMS; var wId = "i_"; var wCB = "priv_JSON_rpc_json_callback_iframe"; var wURL = gJSON_string + "&cb=" + wCB + "×tamp=" + wTS + "&js=y"; // alert(wURL); priv_JSON_callToServer(wURL); } function priv_JSON_callToServer(inURL) { // Function copied from "http://developer.apple.com/internet/webcontent/iframe.html" if (!document.createElement) {return true}; var IFrameDoc; var URL = inURL; if (!gJSON_IFrameObj && document.createElement) { // create the IFrame and assign a reference to the // object to our global variable gJSON_IFrameObj. // this will only happen the first time // priv_JSON_callToServer() is called try { var tempIFrame=document.createElement('iframe'); tempIFrame.setAttribute('id','id_iframe_1'); tempIFrame.style.border='0px'; tempIFrame.style.width='0px'; tempIFrame.style.height='0px'; gJSON_IFrameObj = document.body.appendChild(tempIFrame); if (document.frames) { // this is for IE5 Mac, because it will only // allow access to the document object // of the IFrame if we access it through // the document.frames array gJSON_IFrameObj = document.frames['id_iframe_1']; } } catch(exception) { // This is for IE5 PC, which does not allow dynamic creation // and manipulation of an iframe object. Instead, we'll fake // it up by creating our own objects. iframeHTML='\