Ajax - problem while access on another server URL, but it ok on local

Dear All,i have a problem with a “simple” AJAX code. (see below)

i have a form on my lotus notes web application:

eg:

http://myProductionServer/mydatabase.nsf/TestAjax?OpenForm

on the form i have an HTML button that call an Ajax request on another domain server (non-Domino server):

httpObj.open(“GET”,“server.domain.com/plsql/testconnection”,true);

httpObj.send(null);

So,

The code works correctly if I execute the script on my local web database:

http://localhost/mydatabase.nsf/TestAjax?OpenForm

in this case i stay in a local intranet environment with IE 6 browser, when execute the code the IE ask me a messagebox for “protection problem”…if i click on ‘Yes’ the Ajax code on other domain server is correctly executed e returned (.readyState==4 and .status==200)

If I test the code on the production server:

http://myProductionServer/mydatabase.nsf/TestAjax?OpenForm

i have a javascript error on line:

httpObj.open(“GET”,vurl,true);

javascript error:

‘null’ is null or not an object.

no messagebox for “protection problem” is prompted.

here the sample javascript AJAX code:

doXMLHTTPGet(“server.domain.com/plsql/testconnection”);

function doXMLHTTPGet(vurl) {

var returnData = null;



if (window.XMLHttpRequest) {

	//We are in a non-IE browser

	httpObj=new XMLHttpRequest()

} else if (window.ActiveXObject) {

	//We are in IE

	httpObj=new ActiveXObject("Microsoft.XMLHTTP")

}



document.getElementById("txtmsg").innerHTML = "Check Connection....";



//Return the XML document when it has finished loading

httpObj.onreadystatechange= function()

	{

		if (httpObj.readyState==4)

		{

			if (httpObj.status==200)

			{

				//displayData(httpObj.responseXML);

				alert("Correct Access on MAS Mission");

				

			}

			else

			{

				alert("Problem while accessing MAS Mission:" + httpObj.statusText)

				//document.getElementById("txtmsg").innerHTML = "Problem while accessing MAS Mission:" + httpObj.statusText

			}

		}

	}



//Request the XML document

httpObj.open("GET",vurl,true);

httpObj.send(null)

}

Can you help me ?

Subject: Ajax - problem while access on another server URL, but it ok on local

Hello,i think problem is that normally ajax is unable to work between different domains. It can be cheated if it is running behind you firewall.

Subject: RE: Ajax - problem while access on another server URL, but it ok on local

i think you are right Michal…however,

if i use the lotus script function

GetDocumentByURL(“mydomain/plsql/testconnection”,1)

function, this LS code works perfect.

So,

I can change my Ajax code in ordet to open an agent on my application:

AjaxObj.open(“GET”,“serverdomino/dbnotes.nsf/TestConnection?OpenAgent”,true)

AjaxObj.send(null);

and check this result.

Subject: RE: Ajax - problem while access on another server URL, but it ok on local

It WILL NOT work in the browser. If you need to put information from one domain on a page served by another domain, you need to do it at the server or use a frame.

Subject: RE: Ajax - problem while access on another server URL, but it ok on local

Dear Stan,why should not work ?

in my Ajax code I try to use:

vurl=“http://myserver.domain/mydb.nsf/zTestConnection?OpenAgent

httpObj.open(“GET”,vurl,true);

httpObj.send(null)

in the agent I perform the following LS code:

xurl = “http://myotherdomain/plsql/TestConnection?Parameter1=xxxx

Set docb=db.GetDocumentByURL(xurl,1)

Set item = docb.GetFirstItem (“Body”)

Dim plaintext As String

plaintext = item.GetFormattedText( False, 0 )

If Instr(1,plaintext,“Connection refused”) > 0 Then

Print "Connection Error"

Else

Print "Good"		

End If

the work correctly.

via Ajax I can print the httpObj.responseText comes from the agent.

i think it a good approach !

what do you think about it ?

Subject: It won’t work because of browser security

Search google for cross domain ajax for more details

But your solution is right and what Stan suggested, you have the work happening on your server in the same domain as your ajax page.