» tagged pages
» logout

(Feed found, click Add Page to syndicate.) Error finding feed, please try again » Find feed title

A Blog Page allows you to add entries, for news or other time sensitive postings

(Login required to save to your tagged pages.)
(or Cancel)

Recent Edits

editing re-applied 125.212.29.70

How to use XMLHttpRequest

September 3

h1. Method 1

/** Special IE only code ... */

@end @*/

return xmlhttp;

</pre>

h3. Now you can call XMLHTTPRequest

function getDynamicData()

» complete change

Sample javascript implementing a cross platform xmlhttprequest function:

* Method 1 - Public domain XMLHttpRequest Object[1]

* Method 2 - XHConn, CC-SA XMLHttpRequest Object[2]

Returning Content Through XMLHttpRequest[3]

h1. Method 1

<a name='fn1'></a>

In this method, you can instantiate an XMLHttpRequest object that can then call functions from the server. The code is in the [[license:public domain|public domain]].

<pre>

<code>

function getNewHTTPObject()

{

var xmlhttp;

/** Special IE only code ... */

/*@cc_on

@if (@_jscript_version >= 5)

try

{

xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

}

catch (e)

{

try

{

xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

}

catch (E)

{

xmlhttp = false;

}

}

@else

xmlhttp = false;

@end @*/

/** Every other browser on the planet */

if (!xmlhttp && typeof XMLHttpRequest != 'undefined')

{

try

{

xmlhttp = new XMLHttpRequest();

}

catch (e)

{

xmlhttp = false;

}

}

return xmlhttp;

}

</code>

</pre>

h3. Now you can call XMLHTTPRequest

<pre>

<code>

var xmlHttp = getHTTPObject();

function getDynamicData()

{

var url = "http://url/that/returns/dynamic/content";

xmlHttp.open('GET', url, true);

xmlHttp.onreadystatechange = callbackFunction;

xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

xmlHttp.send(null);

}

</code>

</pre>

h3. The callback function set in xmlHttp.onreadystatechange will be called when data is back from the server

<pre>

<code>

var syndLinkRequest = getNewHTTPObject();

function callbackFunction()

{

if (syndLinkRequest.readyState != 4)

return;

var result = xmlHttp.responseText;

/* if you've returned javascript instead of xml or text,

you can eval(result) to access the javascript variables returned.

*/

}

</code>

</pre>

h1. Method 2 - XHConn

<a name='fn2'></a>

[[XHConn]] is an open source project that attempts to create a very simple and cross platform way to invoke Ajax requests

<pre>

<code>

/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08 **

** Code licensed under Creative Commons Attribution-ShareAlike License **

** http://creativecommons.org/licenses/by-sa/2.0/ **/

function XHConn()

{

var xmlhttp, bComplete = false;

try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }

catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }

catch (e) { try { xmlhttp = new XMLHttpRequest(); }

catch (e) { xmlhttp = false; }}}

if (!xmlhttp) return null;

this.connect = function(sURL, sMethod, sVars, fnDone)

{

if (!xmlhttp) return false;

bComplete = false;

sMethod = sMethod.toUpperCase();

try {

if (sMethod == "GET")

{

xmlhttp.open(sMethod, sURL+"?"+sVars, true);

sVars = "";

}

else

{

xmlhttp.open(sMethod, sURL, true);

xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");

xmlhttp.setRequestHeader("Content-Type",

"application/x-www-form-urlencoded");

}

xmlhttp.onreadystatechange = function(){

if (xmlhttp.readyState == 4 && !bComplete)

{

bComplete = true;

fnDone(xmlhttp);

}};

xmlhttp.send(sVars);

}

catch(z) { return false; }

return true;

};

return this;

}

</code>

</pre>

*Using XHConn:*

<pre>

<code>

//initialize XHConn (if XHConn isn't created successfully,

//the client doesnt' support Ajax)

var ajaxConn = new XHConn();

//post to mypage.php with args foo and baz

ajaxConn.connect("mypage.php", "POST",

"foo=bar&baz=qux",fnWhenDone);

//when the server responds, javascript

//will trigger this callback function

fnWhenDone(XML)

{

alert(XML.responseText);

}

</code>

</pre>

h2. Returning content through the XMLHTTPRequest method:

<a name='fn3'></a>

There are various ways you can return content through [[XMLHTTPRequest]]:

* Plain text (XML.responseText)

* [[Javascript]] variables (eval(XML.responseText))

* [[JSON]] - Javascript objects (eval(XML.responseText))

* [[XML]] (XML.responseText = XML)

Of these, plain text is the simplest, as all it requires is servicing a request with a simple plain text dump of data. The downside to this method is that it's not always a clean way to return more than one variable.

Javascript variables are a nice way to return multiple variables through an XMLHTTPRequest call. Instead of dumping plain text, the server decorates the different returned variables with javascript variable declarations. On the client end, the XMLHTTPRequest callback function evals the server response and now has the variables set by the server available to it as native javascript variables.

One key part of this method however is remembering to escape the content in the javascript variable assignment.

<a hreff="www.sudhakar.byethost4.com">link</a>

The third way of passing back content through XMLHTTPRequest is XML, which despite the name of the function, is often the slowest and most difficult way due to difficulties parsing xml. However for highly structured content or when [[E4X]] becomes more standard, this might be the way to go.

editing undone by 203.112.90.138

How to use XMLHttpRequest

September 2

h1. Method 1

/** Special IE only code ... */

@end @*/

return xmlhttp;

</pre>

h3. Now you can call XMLHTTPRequest

function getDynamicData()

» complete change

Sample javascript implementing a cross platform xmlhttprequest function:

* Method 1 - Public domain XMLHttpRequest Object[1]

* Method 2 - XHConn, CC-SA XMLHttpRequest Object[2]

Returning Content Through XMLHttpRequest[3]

h1. Method 1

<a name='fn1'></a>

In this method, you can instantiate an XMLHttpRequest object that can then call functions from the server. The code is in the [[license:public domain|public domain]].

<pre>

<code>

function getNewHTTPObject()

{

var xmlhttp;

/** Special IE only code ... */

/*@cc_on

@if (@_jscript_version >= 5)

try

{

xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

}

catch (e)

{

try

{

xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

}

catch (E)

{

xmlhttp = false;

}

}

@else

xmlhttp = false;

@end @*/

/** Every other browser on the planet */

if (!xmlhttp && typeof XMLHttpRequest != 'undefined')

{

try

{

xmlhttp = new XMLHttpRequest();

}

catch (e)

{

xmlhttp = false;

}

}

return xmlhttp;

}

</code>

</pre>

h3. Now you can call XMLHTTPRequest

<pre>

<code>

var xmlHttp = getHTTPObject();

function getDynamicData()

{

var url = "http://url/that/returns/dynamic/content";

xmlHttp.open('GET', url, true);

xmlHttp.onreadystatechange = callbackFunction;

xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

xmlHttp.send(null);

}

</code>

</pre>

h3. The callback function set in xmlHttp.onreadystatechange will be called when data is back from the server

<pre>

<code>

var syndLinkRequest = getNewHTTPObject();

function callbackFunction()

{

if (syndLinkRequest.readyState != 4)

return;

var result = xmlHttp.responseText;

/* if you've returned javascript instead of xml or text,

you can eval(result) to access the javascript variables returned.

*/

}

</code>

</pre>

h1. Method 2 - XHConn

<a name='fn2'></a>

[[XHConn]] is an open source project that attempts to create a very simple and cross platform way to invoke Ajax requests

<pre>

<code>

/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08 **

** Code licensed under Creative Commons Attribution-ShareAlike License **

** http://creativecommons.org/licenses/by-sa/2.0/ **/

function XHConn()

{

var xmlhttp, bComplete = false;

try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }

catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }

catch (e) { try { xmlhttp = new XMLHttpRequest(); }

catch (e) { xmlhttp = false; }}}

if (!xmlhttp) return null;

this.connect = function(sURL, sMethod, sVars, fnDone)

{

if (!xmlhttp) return false;

bComplete = false;

sMethod = sMethod.toUpperCase();

try {

if (sMethod == "GET")

{

xmlhttp.open(sMethod, sURL+"?"+sVars, true);

sVars = "";

}

else

{

xmlhttp.open(sMethod, sURL, true);

xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");

xmlhttp.setRequestHeader("Content-Type",

"application/x-www-form-urlencoded");

}

xmlhttp.onreadystatechange = function(){

if (xmlhttp.readyState == 4 && !bComplete)

{

bComplete = true;

fnDone(xmlhttp);

}};

xmlhttp.send(sVars);

}

catch(z) { return false; }

return true;

};

return this;

}

</code>

</pre>

*Using XHConn:*

<pre>

<code>

//initialize XHConn (if XHConn isn't created successfully,

//the client doesnt' support Ajax)

var ajaxConn = new XHConn();

//post to mypage.php with args foo and baz

ajaxConn.connect("mypage.php", "POST",

"foo=bar&baz=qux",fnWhenDone);

//when the server responds, javascript

//will trigger this callback function

fnWhenDone(XML)

{

alert(XML.responseText);

}

</code>

</pre>

h2. Returning content through the XMLHTTPRequest method:

<a name='fn3'></a>

There are various ways you can return content through [[XMLHTTPRequest]]:

* Plain text (XML.responseText)

* [[Javascript]] variables (eval(XML.responseText))

* [[JSON]] - Javascript objects (eval(XML.responseText))

* [[XML]] (XML.responseText = XML)

Of these, plain text is the simplest, as all it requires is servicing a request with a simple plain text dump of data. The downside to this method is that it's not always a clean way to return more than one variable.

Javascript variables are a nice way to return multiple variables through an XMLHTTPRequest call. Instead of dumping plain text, the server decorates the different returned variables with javascript variable declarations. On the client end, the XMLHTTPRequest callback function evals the server response and now has the variables set by the server available to it as native javascript variables.

One key part of this method however is remembering to escape the content in the javascript variable assignment.

<a hreff="www.sudhakar.byethost4.com">link</a>

The third way of passing back content through XMLHTTPRequest is XML, which despite the name of the function, is often the slowest and most difficult way due to difficulties parsing xml. However for highly structured content or when [[E4X]] becomes more standard, this might be the way to go.

editing undone by 203.112.90.138

How to use XMLHttpRequest

September 2

h1. Method 1

/** Special IE only code ... */

@end @*/

return xmlhttp;

</pre>

h3. Now you can call XMLHTTPRequest

function getDynamicData()

» complete change

Sample javascript implementing a cross platform xmlhttprequest function:

* Method 1 - Public domain XMLHttpRequest Object[1]

* Method 2 - XHConn, CC-SA XMLHttpRequest Object[2]

Returning Content Through XMLHttpRequest[3]

h1. Method 1

<a name='fn1'></a>

In this method, you can instantiate an XMLHttpRequest object that can then call functions from the server. The code is in the [[license:public domain|public domain]].

<pre>

<code>

function getNewHTTPObject()

{

var xmlhttp;

/** Special IE only code ... */

/*@cc_on

@if (@_jscript_version >= 5)

try

{

xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

}

catch (e)

{

try

{

xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

}

catch (E)

{

xmlhttp = false;

}

}

@else

xmlhttp = false;

@end @*/

/** Every other browser on the planet */

if (!xmlhttp && typeof XMLHttpRequest != 'undefined')

{

try

{

xmlhttp = new XMLHttpRequest();

}

catch (e)

{

xmlhttp = false;

}

}

return xmlhttp;

}

</code>

</pre>

h3. Now you can call XMLHTTPRequest

<pre>

<code>

var xmlHttp = getHTTPObject();

function getDynamicData()

{

var url = "http://url/that/returns/dynamic/content";

xmlHttp.open('GET', url, true);

xmlHttp.onreadystatechange = callbackFunction;

xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

xmlHttp.send(null);

}

</code>

</pre>

h3. The callback function set in xmlHttp.onreadystatechange will be called when data is back from the server

<pre>

<code>

var syndLinkRequest = getNewHTTPObject();

function callbackFunction()

{

if (syndLinkRequest.readyState != 4)

return;

var result = xmlHttp.responseText;

/* if you've returned javascript instead of xml or text,

you can eval(result) to access the javascript variables returned.

*/

}

</code>

</pre>

h1. Method 2 - XHConn

<a name='fn2'></a>

[[XHConn]] is an open source project that attempts to create a very simple and cross platform way to invoke Ajax requests

<pre>

<code>

/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08 **

** Code licensed under Creative Commons Attribution-ShareAlike License **

** http://creativecommons.org/licenses/by-sa/2.0/ **/

function XHConn()

{

var xmlhttp, bComplete = false;

try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }

catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }

catch (e) { try { xmlhttp = new XMLHttpRequest(); }

catch (e) { xmlhttp = false; }}}

if (!xmlhttp) return null;

this.connect = function(sURL, sMethod, sVars, fnDone)

{

if (!xmlhttp) return false;

bComplete = false;

sMethod = sMethod.toUpperCase();

try {

if (sMethod == "GET")

{

xmlhttp.open(sMethod, sURL+"?"+sVars, true);

sVars = "";

}

else

{

xmlhttp.open(sMethod, sURL, true);

xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");

xmlhttp.setRequestHeader("Content-Type",

"application/x-www-form-urlencoded");

}

xmlhttp.onreadystatechange = function(){

if (xmlhttp.readyState == 4 && !bComplete)

{

bComplete = true;

fnDone(xmlhttp);

}};

xmlhttp.send(sVars);

}

catch(z) { return false; }

return true;

};

return this;

}

</code>

</pre>

*Using XHConn:*

<pre>

<code>

//initialize XHConn (if XHConn isn't created successfully,

//the client doesnt' support Ajax)

var ajaxConn = new XHConn();

//post to mypage.php with args foo and baz

ajaxConn.connect("mypage.php", "POST",

"foo=bar&baz=qux",fnWhenDone);

//when the server responds, javascript

//will trigger this callback function

fnWhenDone(XML)

{

alert(XML.responseText);

}

</code>

</pre>

h2. Returning content through the XMLHTTPRequest method:

<a name='fn3'></a>

There are various ways you can return content through [[XMLHTTPRequest]]:

* Plain text (XML.responseText)

* [[Javascript]] variables (eval(XML.responseText))

* [[JSON]] - Javascript objects (eval(XML.responseText))

* [[XML]] (XML.responseText = XML)

Of these, plain text is the simplest, as all it requires is servicing a request with a simple plain text dump of data. The downside to this method is that it's not always a clean way to return more than one variable.

Javascript variables are a nice way to return multiple variables through an XMLHTTPRequest call. Instead of dumping plain text, the server decorates the different returned variables with javascript variable declarations. On the client end, the XMLHTTPRequest callback function evals the server response and now has the variables set by the server available to it as native javascript variables.

One key part of this method however is remembering to escape the content in the javascript variable assignment.

<a hreff="www.sudhakar.byethost4.com">link</a>

The third way of passing back content through XMLHTTPRequest is XML, which despite the name of the function, is often the slowest and most difficult way due to difficulties parsing xml. However for highly structured content or when [[E4X]] becomes more standard, this might be the way to go.

Undo this change because:
edit by 85.146.210.53

How to use XMLHttpRequest

August 13

h1. Method 1

var xmlhttp;

/** Every other browser on the planet */

{

xmlhttp = new XMLHttpRequest();

return xmlhttp;

</pre>

<pre>

» complete change

Sample javascript implementing a cross platform xmlhttprequest function:

* Method 1 - Public domain XMLHttpRequest Object[1]

* Method 2 - XHConn, CC-SA XMLHttpRequest Object[2]

Returning Content Through XMLHttpRequest[3]

h1. Method 1

<a name='fn1'></a>

In this method, you can instantiate an XMLHttpRequest object that can then call functions from the server. The code is in the [[license:public domain|public domain]].

<pre>

<code>

function getNewHTTPObject()

{

var xmlhttp;

/** Special IE only code ... */

/*@cc_on

@if (@_jscript_version >= 5)

try

{

xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

}

catch (e)

{

try

{

xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

}

catch (E)

{

xmlhttp = false;

}

}

@else

xmlhttp = false;

@end @*/

/** Every other browser on the planet */

if (!xmlhttp && typeof XMLHttpRequest != 'undefined')

{

try

{

xmlhttp = new XMLHttpRequest();

}

catch (e)

{

xmlhttp = false;

}

}

return xmlhttp;

}

</code>

</pre>

h3. Now you can call XMLHTTPRequest

<pre>

<code>

var xmlHttp = getHTTPObject();

function getDynamicData()

{

var url = "http://url/that/returns/dynamic/content";

xmlHttp.open('GET', url, true);

xmlHttp.onreadystatechange = callbackFunction;

xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

xmlHttp.send(null);

}

</code>

</pre>

h3. The callback function set in xmlHttp.onreadystatechange will be called when data is back from the server

<pre>

<code>

var syndLinkRequest = getNewHTTPObject();

function callbackFunction()

{

if (syndLinkRequest.readyState != 4)

return;

var result = xmlHttp.responseText;

/* if you've returned javascript instead of xml or text,

you can eval(result) to access the javascript variables returned.

*/

}

</code>

</pre>

h1. Method 2 - XHConn

<a name='fn2'></a>

[[XHConn]] is an open source project that attempts to create a very simple and cross platform way to invoke Ajax requests

<pre>

<code>

/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08 **

** Code licensed under Creative Commons Attribution-ShareAlike License **

** http://creativecommons.org/licenses/by-sa/2.0/ **/

function XHConn()

{

var xmlhttp, bComplete = false;

try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }

catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }

catch (e) { try { xmlhttp = new XMLHttpRequest(); }

catch (e) { xmlhttp = false; }}}

if (!xmlhttp) return null;

this.connect = function(sURL, sMethod, sVars, fnDone)

{

if (!xmlhttp) return false;

bComplete = false;

sMethod = sMethod.toUpperCase();

try {

if (sMethod == "GET")

{

xmlhttp.open(sMethod, sURL+"?"+sVars, true);

sVars = "";

}

else

{

xmlhttp.open(sMethod, sURL, true);

xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");

xmlhttp.setRequestHeader("Content-Type",

"application/x-www-form-urlencoded");

}

xmlhttp.onreadystatechange = function(){

if (xmlhttp.readyState == 4 && !bComplete)

{

bComplete = true;

fnDone(xmlhttp);

}};

xmlhttp.send(sVars);

}

catch(z) { return false; }

return true;

};

return this;

}

</code>

</pre>

*Using XHConn:*

<pre>

<code>

//initialize XHConn (if XHConn isn't created successfully,

//the client doesnt' support Ajax)

var ajaxConn = new XHConn();

//post to mypage.php with args foo and baz

ajaxConn.connect("mypage.php", "POST",

"foo=bar&baz=qux",fnWhenDone);

//when the server responds, javascript

//will trigger this callback function

fnWhenDone(XML)

{

alert(XML.responseText);

}

</code>

</pre>

h2. Returning content through the XMLHTTPRequest method:

<a name='fn3'></a>

There are various ways you can return content through [[XMLHTTPRequest]]:

* Plain text (XML.responseText)

* [[Javascript]] variables (eval(XML.responseText))

* [[JSON]] - Javascript objects (eval(XML.responseText))

* [[XML]] (XML.responseText = XML)

Of these, plain text is the simplest, as all it requires is servicing a request with a simple plain text dump of data. The downside to this method is that it's not always a clean way to return more than one variable.

Javascript variables are a nice way to return multiple variables through an XMLHTTPRequest call. Instead of dumping plain text, the server decorates the different returned variables with javascript variable declarations. On the client end, the XMLHTTPRequest callback function evals the server response and now has the variables set by the server available to it as native javascript variables.

One key part of this method however is remembering to escape the content in the javascript variable assignment.

<a hreff="www.sudhakar.byethost4.com" target="blank">link</a>

The third way of passing back content through XMLHTTPRequest is XML, which despite the name of the function, is often the slowest and most difficult way due to difficulties parsing xml. However for highly structured content or when [[E4X]] becomes more standard, this might be the way to go.

editing undone by swikster

How to use XMLHttpRequest

May 20

<a hreff="www.sudhakar.byethost4.com" href="www.sudhakar.byethost4.com" target="blank">link</a>

» complete change

Sample javascript implementing a cross platform xmlhttprequest function:

* Method 1 - Public domain XMLHttpRequest Object[1]

* Method 2 - XHConn, CC-SA XMLHttpRequest Object[2]

Returning Content Through XMLHttpRequest[3]

h1. Method 1

<a name='fn1'></a>

In this method, you can instantiate an XMLHttpRequest object that can then call functions from the server. The code is in the [[license:public domain|public domain]].

<pre>

<code>

function getNewHTTPObject()

{

var xmlhttp;

/** Special IE only code ... */

/*@cc_on

@if (@_jscript_version >= 5)

try

{

xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

}

catch (e)

{

try

{

xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

}

catch (E)

{

xmlhttp = false;

}

}

@else

xmlhttp = false;

@end @*/

/** Every other browser on the planet */

if (!xmlhttp && typeof XMLHttpRequest != 'undefined')

{

try

{

xmlhttp = new XMLHttpRequest();

}

catch (e)

{

xmlhttp = false;

}

}

return xmlhttp;

}

</code>

</pre>

h3. Now you can call XMLHTTPRequest

<pre>

<code>

var xmlHttp = getHTTPObject();

function getDynamicData()

{

var url = "http://url/that/returns/dynamic/content";

xmlHttp.open('GET', url, true);

xmlHttp.onreadystatechange = callbackFunction;

xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

xmlHttp.send(null);

}

</code>

</pre>

h3. The callback function set in xmlHttp.onreadystatechange will be called when data is back from the server

<pre>

<code>

var syndLinkRequest = getNewHTTPObject();

function callbackFunction()

{

if (syndLinkRequest.readyState != 4)

return;

var result = xmlHttp.responseText;

/* if you've returned javascript instead of xml or text,

you can eval(result) to access the javascript variables returned.

*/

}

</code>

</pre>

h1. Method 2 - XHConn

<a name='fn2'></a>

[[XHConn]] is an open source project that attempts to create a very simple and cross platform way to invoke Ajax requests

<pre>

<code>

/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08 **

** Code licensed under Creative Commons Attribution-ShareAlike License **

** http://creativecommons.org/licenses/by-sa/2.0/ **/

function XHConn()

{

var xmlhttp, bComplete = false;

try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }

catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }

catch (e) { try { xmlhttp = new XMLHttpRequest(); }

catch (e) { xmlhttp = false; }}}

if (!xmlhttp) return null;

this.connect = function(sURL, sMethod, sVars, fnDone)

{

if (!xmlhttp) return false;

bComplete = false;

sMethod = sMethod.toUpperCase();

try {

if (sMethod == "GET")

{

xmlhttp.open(sMethod, sURL+"?"+sVars, true);

sVars = "";

}

else

{

xmlhttp.open(sMethod, sURL, true);

xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");

xmlhttp.setRequestHeader("Content-Type",

"application/x-www-form-urlencoded");

}

xmlhttp.onreadystatechange = function(){

if (xmlhttp.readyState == 4 && !bComplete)

{

bComplete = true;

fnDone(xmlhttp);

}};

xmlhttp.send(sVars);

}

catch(z) { return false; }

return true;

};

return this;

}

</code>

</pre>

*Using XHConn:*

<pre>

<code>

//initialize XHConn (if XHConn isn't created successfully,

//the client doesnt' support Ajax)

var ajaxConn = new XHConn();

//post to mypage.php with args foo and baz

ajaxConn.connect("mypage.php", "POST",

"foo=bar&baz=qux",fnWhenDone);

//when the server responds, javascript

//will trigger this callback function

fnWhenDone(XML)

{

alert(XML.responseText);

}

</code>

</pre>

h2. Returning content through the XMLHTTPRequest method:

<a name='fn3'></a>

There are various ways you can return content through [[XMLHTTPRequest]]:

* Plain text (XML.responseText)

* [[Javascript]] variables (eval(XML.responseText))

* [[JSON]] - Javascript objects (eval(XML.responseText))

* [[XML]] (XML.responseText = XML)

Of these, plain text is the simplest, as all it requires is servicing a request with a simple plain text dump of data. The downside to this method is that it's not always a clean way to return more than one variable.

Javascript variables are a nice way to return multiple variables through an XMLHTTPRequest call. Instead of dumping plain text, the server decorates the different returned variables with javascript variable declarations. On the client end, the XMLHTTPRequest callback function evals the server response and now has the variables set by the server available to it as native javascript variables.

One key part of this method however is remembering to escape the content in the javascript variable assignment.

<a hreff="www.sudhakar.byethost4.com" href="www.sudhakar.byethost4.com" target="blank">link</a>

The third way of passing back content through XMLHTTPRequest is XML, which despite the name of the function, is often the slowest and most difficult way due to difficulties parsing xml. However for highly structured content or when [[E4X]] becomes more standard, this might be the way to go.

editing undone by swikster

How to use XMLHttpRequest

May 20

Sample javascript implementing a cross platform xmlhttprequest function: dafdasfd

* Method 1 - Public domain XMLHttpRequest...

» complete change

Sample javascript implementing a cross platform xmlhttprequest function: dafdasfd

* Method 1 - Public domain XMLHttpRequest Object[1]

* Method 2 - XHConn, CC-SA XMLHttpRequest Object[2]

Returning Content Through XMLHttpRequest[3]

h1. Method 1

<a name='fn1'></a>

In this method, you can instantiate an XMLHttpRequest object that can then call functions from the server. The code is in the [[license:public domain|public domain]].

<pre>

<code>

function getNewHTTPObject()

{

var xmlhttp;

/** Special IE only code ... */

/*@cc_on

@if (@_jscript_version >= 5)

try

{

xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

}

catch (e)

{

try

{

xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

}

catch (E)

{

xmlhttp = false;

}

}

@else

xmlhttp = false;

@end @*/

/** Every other browser on the planet */

if (!xmlhttp && typeof XMLHttpRequest != 'undefined')

{

try

{

xmlhttp = new XMLHttpRequest();

}

catch (e)

{

xmlhttp = false;

}

}

return xmlhttp;

}

</code>

</pre>

h3. Now you can call XMLHTTPRequest

<pre>

<code>

var xmlHttp = getHTTPObject();

function getDynamicData()

{

var url = "http://url/that/returns/dynamic/content";

xmlHttp.open('GET', url, true);

xmlHttp.onreadystatechange = callbackFunction;

xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

xmlHttp.send(null);

}

</code>

</pre>

h3. The callback function set in xmlHttp.onreadystatechange will be called when data is back from the server

<pre>

<code>

var syndLinkRequest = getNewHTTPObject();

function callbackFunction()

{

if (syndLinkRequest.readyState != 4)

return;

var result = xmlHttp.responseText;

/* if you've returned javascript instead of xml or text,

you can eval(result) to access the javascript variables returned.

*/

}

</code>

</pre>

h1. Method 2 - XHConn

<a name='fn2'></a>

[[XHConn]] is an open source project that attempts to create a very simple and cross platform way to invoke Ajax requests

<pre>

<code>

/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08 **

** Code licensed under Creative Commons Attribution-ShareAlike License **

** http://creativecommons.org/licenses/by-sa/2.0/ **/

function XHConn()

{

var xmlhttp, bComplete = false;

try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }

catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }

catch (e) { try { xmlhttp = new XMLHttpRequest(); }

catch (e) { xmlhttp = false; }}}

if (!xmlhttp) return null;

this.connect = function(sURL, sMethod, sVars, fnDone)

{

if (!xmlhttp) return false;

bComplete = false;

sMethod = sMethod.toUpperCase();

try {

if (sMethod == "GET")

{

xmlhttp.open(sMethod, sURL+"?"+sVars, true);

sVars = "";

}

else

{

xmlhttp.open(sMethod, sURL, true);

xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");

xmlhttp.setRequestHeader("Content-Type",

"application/x-www-form-urlencoded");

}

xmlhttp.onreadystatechange = function(){

if (xmlhttp.readyState == 4 && !bComplete)

{

bComplete = true;

fnDone(xmlhttp);

}};

xmlhttp.send(sVars);

}

catch(z) { return false; }

return true;

};

return this;

}

</code>

</pre>

*Using XHConn:*

<pre>

<code>

//initialize XHConn (if XHConn isn't created successfully,

//the client doesnt' support Ajax)

var ajaxConn = new XHConn();

//post to mypage.php with args foo and baz

ajaxConn.connect("mypage.php", "POST",

"foo=bar&baz=qux",fnWhenDone);

//when the server responds, javascript

//will trigger this callback function

fnWhenDone(XML)

{

alert(XML.responseText);

}

</code>

</pre>

h2. Returning content through the XMLHTTPRequest method:

<a name='fn3'></a>

There are various ways you can return content through [[XMLHTTPRequest]]:

* Plain text (XML.responseText)

* [[Javascript]] variables (eval(XML.responseText))

* [[JSON]] - Javascript objects (eval(XML.responseText))

* [[XML]] (XML.responseText = XML)

Of these, plain text is the simplest, as all it requires is servicing a request with a simple plain text dump of data. The downside to this method is that it's not always a clean way to return more than one variable.

Javascript variables are a nice way to return multiple variables through an XMLHTTPRequest call. Instead of dumping plain text, the server decorates the different returned variables with javascript variable declarations. On the client end, the XMLHTTPRequest callback function evals the server response and now has the variables set by the server available to it as native javascript variables.

One key part of this method however is remembering to escape the content in the javascript variable assignment.

<a href="www.sudhakar.byethost4.com" target="blank">link</a>

The third way of passing back content through XMLHTTPRequest is XML, which despite the name of the function, is often the slowest and most difficult way due to difficulties parsing xml. However for highly structured content or when [[E4X]] becomes more standard, this might be the way to go.

editing undone by swikster

How to use XMLHttpRequest

May 20

dafdasfd dafdasfdasdasd

editing undone by swikster

How to use XMLHttpRequest

May 20

dafdasfdasdasd dafdasf"

editing undone by swikster

How to use XMLHttpRequest

May 20

dafdasf" <div class='menu_item' onclick="searchcity('Seoul')">bbb</div>

How to use XMLHttpRequest

May 17

<div class='menu_item' onclick="searchcity('Seoul')">bbb</div> dafdasf"

How to use XMLHttpRequest

May 17

dafdasf" dafdasfdasdasd

edit by 116.48.52.22

How to use XMLHttpRequest

May 17

dafdasfdasdasd dafdasfd

How to use XMLHttpRequest

May 16

dafdasfd Sample javascript implementing a cross platform xmlhttprequest function:

* Method 1 - Public domain XMLHttpRequest...

» complete change

dafdasfd Sample javascript implementing a cross platform xmlhttprequest function:

* Method 1 - Public domain XMLHttpRequest Object[1]

* Method 2 - XHConn, CC-SA XMLHttpRequest Object[2]

Returning Content Through XMLHttpRequest[3]

h1. Method 1

<a name='fn1'></a>

In this method, you can instantiate an XMLHttpRequest object that can then call functions from the server. The code is in the [[license:public domain|public domain]].

<pre>

<code>

function getNewHTTPObject()

{

var xmlhttp;

/** Special IE only code ... */

/*@cc_on

@if (@_jscript_version >= 5)

try

{

xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

}

catch (e)

{

try

{

xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

}

catch (E)

{

xmlhttp = false;

}

}

@else

xmlhttp = false;

@end @*/

/** Every other browser on the planet */

if (!xmlhttp && typeof XMLHttpRequest != 'undefined')

{

try

{

xmlhttp = new XMLHttpRequest();

}

catch (e)

{

xmlhttp = false;

}

}

return xmlhttp;

}

</code>

</pre>

h3. Now you can call XMLHTTPRequest

<pre>

<code>

var xmlHttp = getHTTPObject();

function getDynamicData()

{

var url = "http://url/that/returns/dynamic/content";

xmlHttp.open('GET', url, true);

xmlHttp.onreadystatechange = callbackFunction;

xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

xmlHttp.send(null);

}

</code>

</pre>

h3. The callback function set in xmlHttp.onreadystatechange will be called when data is back from the server

<pre>

<code>

var syndLinkRequest = getNewHTTPObject();

function callbackFunction()

{

if (syndLinkRequest.readyState != 4)

return;

var result = xmlHttp.responseText;

/* if you've returned javascript instead of xml or text,

you can eval(result) to access the javascript variables returned.

*/

}

</code>

</pre>

h1. Method 2 - XHConn

<a name='fn2'></a>

[[XHConn]] is an open source project that attempts to create a very simple and cross platform way to invoke Ajax requests

<pre>

<code>

/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08 **

** Code licensed under Creative Commons Attribution-ShareAlike License **

** http://creativecommons.org/licenses/by-sa/2.0/ **/

function XHConn()

{

var xmlhttp, bComplete = false;

try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }

catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }

catch (e) { try { xmlhttp = new XMLHttpRequest(); }

catch (e) { xmlhttp = false; }}}

if (!xmlhttp) return null;

this.connect = function(sURL, sMethod, sVars, fnDone)

{

if (!xmlhttp) return false;

bComplete = false;

sMethod = sMethod.toUpperCase();

try {

if (sMethod == "GET")

{

xmlhttp.open(sMethod, sURL+"?"+sVars, true);

sVars = "";

}

else

{

xmlhttp.open(sMethod, sURL, true);

xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");

xmlhttp.setRequestHeader("Content-Type",

"application/x-www-form-urlencoded");

}

xmlhttp.onreadystatechange = function(){

if (xmlhttp.readyState == 4 && !bComplete)

{

bComplete = true;

fnDone(xmlhttp);

}};

xmlhttp.send(sVars);

}

catch(z) { return false; }

return true;

};

return this;

}

</code>

</pre>

*Using XHConn:*

<pre>

<code>

//initialize XHConn (if XHConn isn't created successfully,

//the client doesnt' support Ajax)

var ajaxConn = new XHConn();

//post to mypage.php with args foo and baz

ajaxConn.connect("mypage.php", "POST",

"foo=bar&baz=qux",fnWhenDone);

//when the server responds, javascript

//will trigger this callback function

fnWhenDone(XML)

{

alert(XML.responseText);

}

</code>

</pre>

h2. Returning content through the XMLHTTPRequest method:

<a name='fn3'></a>

There are various ways you can return content through [[XMLHTTPRequest]]:

* Plain text (XML.responseText)

* [[Javascript]] variables (eval(XML.responseText))

* [[JSON]] - Javascript objects (eval(XML.responseText))

* [[XML]] (XML.responseText = XML)

Of these, plain text is the simplest, as all it requires is servicing a request with a simple plain text dump of data. The downside to this method is that it's not always a clean way to return more than one variable.

Javascript variables are a nice way to return multiple variables through an XMLHTTPRequest call. Instead of dumping plain text, the server decorates the different returned variables with javascript variable declarations. On the client end, the XMLHTTPRequest callback function evals the server response and now has the variables set by the server available to it as native javascript variables.

One key part of this method however is remembering to escape the content in the javascript variable assignment.

<a href="www.sudhakar.byethost4.com" target="blank">link</a>

The third way of passing back content through XMLHTTPRequest is XML, which despite the name of the function, is often the slowest and most difficult way due to difficulties parsing xml. However for highly structured content or when [[E4X]] becomes more standard, this might be the way to go.

edit by 76.27.10.129

How to use XMLHttpRequest

May 15

<a href="www.sudhakar.byethost4.com" hreff="www.sudhakar.byethost4.com" target="blank">link</a>

» complete change

Sample javascript implementing a cross platform xmlhttprequest function:

* Method 1 - Public domain XMLHttpRequest Object[1]

* Method 2 - XHConn, CC-SA XMLHttpRequest Object[2]

Returning Content Through XMLHttpRequest[3]

h1. Method 1

<a name='fn1'></a>

In this method, you can instantiate an XMLHttpRequest object that can then call functions from the server. The code is in the [[license:public domain|public domain]].

<pre>

<code>

function getNewHTTPObject()

{

var xmlhttp;

/** Special IE only code ... */

/*@cc_on

@if (@_jscript_version >= 5)

try

{

xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

}

catch (e)

{

try

{

xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

}

catch (E)

{

xmlhttp = false;

}

}

@else

xmlhttp = false;

@end @*/

/** Every other browser on the planet */

if (!xmlhttp && typeof XMLHttpRequest != 'undefined')

{

try

{

xmlhttp = new XMLHttpRequest();

}

catch (e)

{

xmlhttp = false;

}

}

return xmlhttp;

}

</code>

</pre>

h3. Now you can call XMLHTTPRequest

<pre>

<code>

var xmlHttp = getHTTPObject();

function getDynamicData()

{

var url = "http://url/that/returns/dynamic/content";

xmlHttp.open('GET', url, true);

xmlHttp.onreadystatechange = callbackFunction;

xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

xmlHttp.send(null);

}

</code>

</pre>

h3. The callback function set in xmlHttp.onreadystatechange will be called when data is back from the server

<pre>

<code>

var syndLinkRequest = getNewHTTPObject();

function callbackFunction()

{

if (syndLinkRequest.readyState != 4)

return;

var result = xmlHttp.responseText;

/* if you've returned javascript instead of xml or text,

you can eval(result) to access the javascript variables returned.

*/

}

</code>

</pre>

h1. Method 2 - XHConn

<a name='fn2'></a>

[[XHConn]] is an open source project that attempts to create a very simple and cross platform way to invoke Ajax requests

<pre>

<code>

/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08 **

** Code licensed under Creative Commons Attribution-ShareAlike License **

** http://creativecommons.org/licenses/by-sa/2.0/ **/

function XHConn()

{

var xmlhttp, bComplete = false;

try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }

catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }

catch (e) { try { xmlhttp = new XMLHttpRequest(); }

catch (e) { xmlhttp = false; }}}

if (!xmlhttp) return null;

this.connect = function(sURL, sMethod, sVars, fnDone)

{

if (!xmlhttp) return false;

bComplete = false;

sMethod = sMethod.toUpperCase();

try {

if (sMethod == "GET")

{

xmlhttp.open(sMethod, sURL+"?"+sVars, true);

sVars = "";

}

else

{

xmlhttp.open(sMethod, sURL, true);

xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");

xmlhttp.setRequestHeader("Content-Type",

"application/x-www-form-urlencoded");

}

xmlhttp.onreadystatechange = function(){

if (xmlhttp.readyState == 4 && !bComplete)

{

bComplete = true;

fnDone(xmlhttp);

}};

xmlhttp.send(sVars);

}

catch(z) { return false; }

return true;

};

return this;

}

</code>

</pre>

*Using XHConn:*

<pre>

<code>

//initialize XHConn (if XHConn isn't created successfully,

//the client doesnt' support Ajax)

var ajaxConn = new XHConn();

//post to mypage.php with args foo and baz

ajaxConn.connect("mypage.php", "POST",

"foo=bar&baz=qux",fnWhenDone);

//when the server responds, javascript

//will trigger this callback function

fnWhenDone(XML)

{

alert(XML.responseText);

}

</code>

</pre>

h2. Returning content through the XMLHTTPRequest method:

<a name='fn3'></a>

There are various ways you can return content through [[XMLHTTPRequest]]:

* Plain text (XML.responseText)

* [[Javascript]] variables (eval(XML.responseText))

* [[JSON]] - Javascript objects (eval(XML.responseText))

* [[XML]] (XML.responseText = XML)

Of these, plain text is the simplest, as all it requires is servicing a request with a simple plain text dump of data. The downside to this method is that it's not always a clean way to return more than one variable.

Javascript variables are a nice way to return multiple variables through an XMLHTTPRequest call. Instead of dumping plain text, the server decorates the different returned variables with javascript variable declarations. On the client end, the XMLHTTPRequest callback function evals the server response and now has the variables set by the server available to it as native javascript variables.

One key part of this method however is remembering to escape the content in the javascript variable assignment.

<a href="www.sudhakar.byethost4.com" hreff="www.sudhakar.byethost4.com" target="blank">link</a>

The third way of passing back content through XMLHTTPRequest is XML, which despite the name of the function, is often the slowest and most difficult way due to difficulties parsing xml. However for highly structured content or when [[E4X]] becomes more standard, this might be the way to go.

editing undone by 122.152.136.170

How to use XMLHttpRequest

May 13
“aaa”

The third way of passing back content through XMLHTTPRequest is XML, which despite the name of the function, is often the...

» complete change

Sample javascript implementing a cross platform xmlhttprequest function:

* Method 1 - Public domain XMLHttpRequest Object[1]

* Method 2 - XHConn, CC-SA XMLHttpRequest Object[2]

Returning Content Through XMLHttpRequest[3]

h1. Method 1

<a name='fn1'></a>

In this method, you can instantiate an XMLHttpRequest object that can then call functions from the server. The code is in the [[license:public domain|public domain]].

<pre>

<code>

function getNewHTTPObject()

{

var xmlhttp;

/** Special IE only code ... */

/*@cc_on

@if (@_jscript_version >= 5)

try

{

xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

}

catch (e)

{

try

{

xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

}

catch (E)

{

xmlhttp = false;

}

}

@else

xmlhttp = false;

@end @*/

/** Every other browser on the planet */

if (!xmlhttp && typeof XMLHttpRequest != 'undefined')

{

try

{

xmlhttp = new XMLHttpRequest();

}

catch (e)

{

xmlhttp = false;

}

}

return xmlhttp;

}

</code>

</pre>

h3. Now you can call XMLHTTPRequest

<pre>

<code>

var xmlHttp = getHTTPObject();

function getDynamicData()

{

var url = "http://url/that/returns/dynamic/content";

xmlHttp.open('GET', url, true);

xmlHttp.onreadystatechange = callbackFunction;

xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

xmlHttp.send(null);

}

</code>

</pre>

h3. The callback function set in xmlHttp.onreadystatechange will be called when data is back from the server

<pre>

<code>

var syndLinkRequest = getNewHTTPObject();

function callbackFunction()

{

if (syndLinkRequest.readyState != 4)

return;

var result = xmlHttp.responseText;

/* if you've returned javascript instead of xml or text,

you can eval(result) to access the javascript variables returned.

*/

}

</code>

</pre>

h1. Method 2 - XHConn

<a name='fn2'></a>

[[XHConn]] is an open source project that attempts to create a very simple and cross platform way to invoke Ajax requests

<pre>

<code>

/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08 **

** Code licensed under Creative Commons Attribution-ShareAlike License **

** http://creativecommons.org/licenses/by-sa/2.0/ **/

function XHConn()

{

var xmlhttp, bComplete = false;

try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }

catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }

catch (e) { try { xmlhttp = new XMLHttpRequest(); }

catch (e) { xmlhttp = false; }}}

if (!xmlhttp) return null;

this.connect = function(sURL, sMethod, sVars, fnDone)

{

if (!xmlhttp) return false;

bComplete = false;

sMethod = sMethod.toUpperCase();

try {

if (sMethod == "GET")

{

xmlhttp.open(sMethod, sURL+"?"+sVars, true);

sVars = "";

}

else

{

xmlhttp.open(sMethod, sURL, true);

xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");

xmlhttp.setRequestHeader("Content-Type",

"application/x-www-form-urlencoded");

}

xmlhttp.onreadystatechange = function(){

if (xmlhttp.readyState == 4 && !bComplete)

{

bComplete = true;

fnDone(xmlhttp);

}};

xmlhttp.send(sVars);

}

catch(z) { return false; }

return true;

};

return this;

}

</code>

</pre>

*Using XHConn:*

<pre>

<code>

//initialize XHConn (if XHConn isn't created successfully,

//the client doesnt' support Ajax)

var ajaxConn = new XHConn();

//post to mypage.php with args foo and baz

ajaxConn.connect("mypage.php", "POST",

"foo=bar&baz=qux",fnWhenDone);

//when the server responds, javascript

//will trigger this callback function

fnWhenDone(XML)

{

alert(XML.responseText);

}

</code>

</pre>

h2. Returning content through the XMLHTTPRequest method:

<a name='fn3'></a>

There are various ways you can return content through [[XMLHTTPRequest]]:

* Plain text (XML.responseText)

* [[Javascript]] variables (eval(XML.responseText))

* [[JSON]] - Javascript objects (eval(XML.responseText))

* [[XML]] (XML.responseText = XML)

Of these, plain text is the simplest, as all it requires is servicing a request with a simple plain text dump of data. The downside to this method is that it's not always a clean way to return more than one variable.

Javascript variables are a nice way to return multiple variables through an XMLHTTPRequest call. Instead of dumping plain text, the server decorates the different returned variables with javascript variable declarations. On the client end, the XMLHTTPRequest callback function evals the server response and now has the variables set by the server available to it as native javascript variables.

One key part of this method however is remembering to escape the content in the javascript variable assignment.

<a hreff="www.sudhakar.byethost4.com" target="blank">link</a>

The third way of passing back content through XMLHTTPRequest is XML, which despite the name of the function, is often the slowest and most difficult way due to difficulties parsing xml. However for highly structured content or when [[E4X]] becomes more standard, this might be the way to go. "link":http://www.sudhakar.byethost4.com.

How to use XMLHttpRequest

April 23

h1. Method 1

/** Special IE only code ... */

@end @*/

return xmlhttp;

</pre>

h3. Now you can call XMLHTTPRequest

function getDynamicData()

» complete change

Sample javascript implementing a cross platform xmlhttprequest function:

* Method 1 - Public domain XMLHttpRequest Object[1]

* Method 2 - XHConn, CC-SA XMLHttpRequest Object[2]

Returning Content Through XMLHttpRequest[3]

h1. Method 1

<a name='fn1'></a>

In this method, you can instantiate an XMLHttpRequest object that can then call functions from the server. The code is in the [[license:public domain|public domain]].

<pre>

<code>

function getNewHTTPObject()

{

var xmlhttp;

/** Special IE only code ... */

/*@cc_on

@if (@_jscript_version >= 5)

try

{

xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

}

catch (e)

{

try

{

xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

}

catch (E)

{

xmlhttp = false;

}

}

@else

xmlhttp = false;

@end @*/

/** Every other browser on the planet */

if (!xmlhttp && typeof XMLHttpRequest != 'undefined')

{

try

{

xmlhttp = new XMLHttpRequest();

}

catch (e)

{

xmlhttp = false;

}

}

return xmlhttp;

}

</code>

</pre>

h3. Now you can call XMLHTTPRequest

<pre>

<code>

var xmlHttp = getHTTPObject();

function getDynamicData()

{

var url = "http://url/that/returns/dynamic/content";

xmlHttp.open('GET', url, true);

xmlHttp.onreadystatechange = callbackFunction;

xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

xmlHttp.send(null);

}

</code>

</pre>

h3. The callback function set in xmlHttp.onreadystatechange will be called when data is back from the server

<pre>

<code>

var syndLinkRequest = getNewHTTPObject();

function callbackFunction()

{

if (syndLinkRequest.readyState != 4)

return;

var result = xmlHttp.responseText;

/* if you've returned javascript instead of xml or text,

you can eval(result) to access the javascript variables returned.

*/

}

</code>

</pre>

h1. Method 2 - XHConn

<a name='fn2'></a>

[[XHConn]] is an open source project that attempts to create a very simple and cross platform way to invoke Ajax requests

<pre>

<code>

/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08 **

** Code licensed under Creative Commons Attribution-ShareAlike License **

** http://creativecommons.org/licenses/by-sa/2.0/ **/

function XHConn()

{

var xmlhttp, bComplete = false;

try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }

catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }

catch (e) { try { xmlhttp = new XMLHttpRequest(); }

catch (e) { xmlhttp = false; }}}

if (!xmlhttp) return null;

this.connect = function(sURL, sMethod, sVars, fnDone)

{

if (!xmlhttp) return false;

bComplete = false;

sMethod = sMethod.toUpperCase();

try {

if (sMethod == "GET")

{

xmlhttp.open(sMethod, sURL+"?"+sVars, true);

sVars = "";

}

else

{

xmlhttp.open(sMethod, sURL, true);

xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");

xmlhttp.setRequestHeader("Content-Type",

"application/x-www-form-urlencoded");

}

xmlhttp.onreadystatechange = function(){

if (xmlhttp.readyState == 4 && !bComplete)

{

bComplete = true;

fnDone(xmlhttp);

}};

xmlhttp.send(sVars);

}

catch(z) { return false; }

return true;

};

return this;

}

</code>

</pre>

*Using XHConn:*

<pre>

<code>

//initialize XHConn (if XHConn isn't created successfully,

//the client doesnt' support Ajax)

var ajaxConn = new XHConn();

//post to mypage.php with args foo and baz

ajaxConn.connect("mypage.php", "POST",

"foo=bar&baz=qux",fnWhenDone);

//when the server responds, javascript

//will trigger this callback function

fnWhenDone(XML)

{

alert(XML.responseText);

}

</code>

</pre>

h2. Returning content through the XMLHTTPRequest method:

<a name='fn3'></a>

There are various ways you can return content through [[XMLHTTPRequest]]:

* Plain text (XML.responseText)

* [[Javascript]] variables (eval(XML.responseText))

* [[JSON]] - Javascript objects (eval(XML.responseText))

* [[XML]] (XML.responseText = XML)

Of these, plain text is the simplest, as all it requires is servicing a request with a simple plain text dump of data. The downside to this method is that it's not always a clean way to return more than one variable.

Javascript variables are a nice way to return multiple variables through an XMLHTTPRequest call. Instead of dumping plain text, the server decorates the different returned variables with javascript variable declarations. On the client end, the XMLHTTPRequest callback function evals the server response and now has the variables set by the server available to it as native javascript variables.

One key part of this method however is remembering to escape the content in the javascript variable assignment.

<a hreff="www.sudhakar.byethost4.com">link</a>

The third way of passing back content through XMLHTTPRequest is XML, which despite the name of the function, is often the slowest and most difficult way due to difficulties parsing xml. However for highly structured content or when [[E4X]] becomes more standard, this might be the way to go.

How to use XMLHttpRequest

March 27

h1. Method 1

/** Special IE only code ... */

@end @*/

return xmlhttp;

</pre>

h3. Now you can call XMLHTTPRequest

function getDynamicData()

» complete change

Sample javascript implementing a cross platform xmlhttprequest function:

* Method 1 - Public domain XMLHttpRequest Object[1]

* Method 2 - XHConn, CC-SA XMLHttpRequest Object[2]

Returning Content Through XMLHttpRequest[3]

h1. Method 1

<a name='fn1'></a>

In this method, you can instantiate an XMLHttpRequest object that can then call functions from the server. The code is in the [[license:public domain|public domain]].

<pre>

<code>

function getNewHTTPObject()

{

var xmlhttp;

/** Special IE only code ... */

/*@cc_on

@if (@_jscript_version >= 5)

try

{

xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

}

catch (e)

{

try

{

xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

}

catch (E)

{

xmlhttp = false;

}

}

@else

xmlhttp = false;

@end @*/

/** Every other browser on the planet */

if (!xmlhttp && typeof XMLHttpRequest != 'undefined')

{

try

{

xmlhttp = new XMLHttpRequest();

}

catch (e)

{

xmlhttp = false;

}

}

return xmlhttp;

}

</code>

</pre>

h3. Now you can call XMLHTTPRequest

<pre>

<code>

var xmlHttp = getHTTPObject();

function getDynamicData()

{

var url = "http://url/that/returns/dynamic/content";

xmlHttp.open('GET', url, true);

xmlHttp.onreadystatechange = callbackFunction;

xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

xmlHttp.send(null);

}

</code>

</pre>

h3. The callback function set in xmlHttp.onreadystatechange will be called when data is back from the server

<pre>

<code>

var syndLinkRequest = getNewHTTPObject();

function callbackFunction()

{

if (syndLinkRequest.readyState != 4)

return;

var result = xmlHttp.responseText;

/* if you've returned javascript instead of xml or text,

you can eval(result) to access the javascript variables returned.

*/

}

</code>

</pre>

h1. Method 2 - XHConn

<a name='fn2'></a>

[[XHConn]] is an open source project that attempts to create a very simple and cross platform way to invoke Ajax requests

<pre>

<code>

/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08 **

** Code licensed under Creative Commons Attribution-ShareAlike License **

** http://creativecommons.org/licenses/by-sa/2.0/ **/

function XHConn()

{

var xmlhttp, bComplete = false;

try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }

catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }

catch (e) { try { xmlhttp = new XMLHttpRequest(); }

catch (e) { xmlhttp = false; }}}

if (!xmlhttp) return null;

this.connect = function(sURL, sMethod, sVars, fnDone)

{

if (!xmlhttp) return false;

bComplete = false;

sMethod = sMethod.toUpperCase();

try {

if (sMethod == "GET")

{

xmlhttp.open(sMethod, sURL+"?"+sVars, true);

sVars = "";

}

else

{

xmlhttp.open(sMethod, sURL, true);

xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");

xmlhttp.setRequestHeader("Content-Type",

"application/x-www-form-urlencoded");

}

xmlhttp.onreadystatechange = function(){

if (xmlhttp.readyState == 4 && !bComplete)

{

bComplete = true;

fnDone(xmlhttp);

}};

xmlhttp.send(sVars);

}

catch(z) { return false; }

return true;

};

return this;

}

</code>

</pre>

*Using XHConn:*

<pre>

<code>

//initialize XHConn (if XHConn isn't created successfully,

//the client doesnt' support Ajax)

var ajaxConn = new XHConn();

//post to mypage.php with args foo and baz

ajaxConn.connect("mypage.php", "POST",

"foo=bar&baz=qux",fnWhenDone);

//when the server responds, javascript

//will trigger this callback function

fnWhenDone(XML)

{

alert(XML.responseText);

}

</code>

</pre>

h2. Returning content through the XMLHTTPRequest method:

<a name='fn3'></a>

There are various ways you can return content through [[XMLHTTPRequest]]:

* Plain text