org.symbian.tools.wrttools/projecttemplates/WRTKit/UI/Ajax.js
changeset 309 c01f5ab28a11
parent 308 c521df56b15d
child 310 e9484be98cfe
equal deleted inserted replaced
308:c521df56b15d 309:c01f5ab28a11
     1 /**
       
     2  * Copyright (c) 2009-2010 Symbian Foundation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of the License "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  * 
       
    12  * Contributors:
       
    13  * 
       
    14  * Description:
       
    15  * 
       
    16  */
       
    17 
       
    18 ///////////////////////////////////////////////////////////////////////////////
       
    19 // Ajax utility calss to create XmlHttpRequest object
       
    20 function Ajax() 
       
    21 {
       
    22 	//	xmlHttpRequest object	
       
    23 	var request = null;
       
    24 
       
    25     // branch for native XMLHttpRequest object
       
    26     if(window.XMLHttpRequest && !(window.ActiveXObject)) {
       
    27     	try 
       
    28 		{
       
    29 			request = new XMLHttpRequest();
       
    30 			try
       
    31 			{
       
    32 				//	attach the Bypass code, if the browser is firefox
       
    33 				if(netscape.security.PrivilegeManager.enablePrivilege)
       
    34 				{
       
    35 					//	duplicate the function
       
    36 					request._open = request.open;
       
    37 					
       
    38 					//	redefine the function definition
       
    39 					request.open = function(method, url, flag)
       
    40 					{
       
    41 						try
       
    42 						{
       
    43 							// Enable Universal Browser Read
       
    44 							netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
       
    45 
       
    46 							//	call the native XmlHttpRequest.open method
       
    47 							this._open(method, url, flag);
       
    48 						}catch(e)
       
    49 						{
       
    50 							//	call the native XmlHttpRequest.open method
       
    51 							this._open(method, url, flag);
       
    52 						}
       
    53 					};
       
    54 				}
       
    55 			}
       
    56 			catch(e)
       
    57 			{
       
    58 				//	eatup all exceptions
       
    59 			}
       
    60 		} 
       
    61 		catch(e) {
       
    62 			request = null;
       
    63         }
       
    64     // branch for IE/Windows ActiveX version
       
    65     } else if(window.ActiveXObject) {
       
    66        	try {
       
    67         	request = new ActiveXObject("Msxml2.XMLHTTP");
       
    68       	} catch(e) {
       
    69         	try {
       
    70           		request = new ActiveXObject("Microsoft.XMLHTTP");
       
    71         	} catch(e) {
       
    72           		alert('Failed to create XmlHttprequest');
       
    73 				return null;
       
    74         	}
       
    75 		}
       
    76     }
       
    77 	
       
    78 	return (request);
       
    79 }