<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Code Reference &#187; Ajax</title>
	<atom:link href="http://sullivan.net/blog/tag/ajax/feed/" rel="self" type="application/rss+xml" />
	<link>http://sullivan.net/blog</link>
	<description>A collection of code for my reference (and perhaps other people too)</description>
	<lastBuildDate>Wed, 25 Jan 2012 17:53:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>GET and POST with JavaScript &#8211; with XMLHttpRequest</title>
		<link>http://sullivan.net/blog/2010/02/get-and-post-with-javascript-with-xmlhttprequest/</link>
		<comments>http://sullivan.net/blog/2010/02/get-and-post-with-javascript-with-xmlhttprequest/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 09:51:28 +0000</pubDate>
		<dc:creator>Darren</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[Ajax]]></category>

		<guid isPermaLink="false">http://sullivan.net/blog/?p=255</guid>
		<description><![CDATA[This is an example on how to make a POST call to a WCF service using JavaScript. Notice the XML to send is passed thru in the 'send' method. The XML type must be sent if you are sending XML. &#60;!DOCTYPE html PUBLIC &#34;-//W3C//DTD XHTML 1.0 Transitional//EN&#34; &#34;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#34;&#62; &#60;html xmlns=&#34;http://www.w3.org/1999/xhtml&#34;&#62; &#60;head&#62; &#60;title&#62;&#60;/title&#62; &#60;script type=&#34;text/javascript&#34;&#62; var [...]]]></description>
			<content:encoded><![CDATA[<p>This is an example on how to make a POST call to a WCF service using JavaScript. Notice the XML to send is passed thru in the 'send' method. The XML type must be sent if you are sending XML.</p>
<pre class="brush: html">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;

&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
    &lt;title&gt;&lt;/title&gt;
    &lt;script type=&quot;text/javascript&quot;&gt;
        var url = &#039;http://example.com/myservice&#039;;
        var xml = &#039;&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;&lt;Root xmlns=&quot;http://schemas.datacontract.org/2004/07/MyServiceDomain&quot;&gt;&lt;Name&gt;John&lt;/Name&gt;&lt;Language&gt;UK&lt;/Langguage&gt;&lt;/Root&gt;&#039;;

        function getHTTPObject() {
            if (typeof XMLHttpRequest != &#039;undefined&#039;) {
                return new XMLHttpRequest();
            }
            try {
                return new ActiveXObject(&quot;Msxml2.XMLHTTP&quot;);
            } catch (e) {
                try {
                    return new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);
                } catch (e) { }
            }
            return false;
        }

        function useHttpResponse() {
            if (http.readyState == 4) {
                var textout = http.responseText;
                doSomething(textout);
            }
        }

        function doSomething(textout) {
            alert(textout);
        }

        var http = getHTTPObject();
        http.open(&quot;POST&quot;, url, true);
        http.setRequestHeader(&quot;Content-type&quot;, &quot;text/xml&quot;);
        http.onreadystatechange = useHttpResponse;
        http.send(xml);

    &lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>NOTE: You cannot make calls to services or files outside your local domain. If you wish to call a service from another domain (for example a Yahoo or Google service), you must create a proxy page that calls the external service. Your JavaScript will call your proxy page.</p>
<p>Here is an example of a GET call. Notice that the URL and the request parameters are sent thru in the 'open' method. The 'send' method has no arguments.</p>
<pre class="brush: html">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;

&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
    &lt;title&gt;&lt;/title&gt;
    &lt;script type=&quot;text/javascript&quot;&gt;
        var url = &#039;http://example.com/myservice.php?name=John&amp;Language=UK&#039;;

        function getHTTPObject() {
            if (typeof XMLHttpRequest != &#039;undefined&#039;) {
                return new XMLHttpRequest();
            }
            try {
                return new ActiveXObject(&quot;Msxml2.XMLHTTP&quot;);
            } catch (e) {
                try {
                    return new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);
                } catch (e) { }
            }
            return false;
        }

        function useHttpResponse() {
            if (http.readyState == 4) {
                var textout = http.responseText;
                doSomething(textout);
            }
        }

        function doSomething(textout) {
            alert(textout);
        }

        var http = getHTTPObject();
        http.open(&quot;GET&quot;, url, true);
        http.onreadystatechange = useHttpResponse;
        http.send();

    &lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://sullivan.net/blog/2010/02/get-and-post-with-javascript-with-xmlhttprequest/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

