<?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>Sarawut Ninsawat &#187; AJAX</title>
	<atom:link href="https://www.ninsawat.com/?cat=13&#038;feed=rss2" rel="self" type="application/rss+xml" />
	<link>https://www.ninsawat.com</link>
	<description>A Personal Blog but not private</description>
	<lastBuildDate>Sat, 02 Aug 2025 08:02:05 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.9.2</generator>
	<item>
		<title>AJAX Cross-Domain Request</title>
		<link>https://www.ninsawat.com/?p=29&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ajax-cross-domain-request</link>
		<comments>https://www.ninsawat.com/?p=29#comments</comments>
		<pubDate>Fri, 19 Oct 2007 05:15:00 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[cross-domain]]></category>

		<guid isPermaLink="false">http://www.ninsawat.com/?p=29</guid>
		<description><![CDATA[หลังจากที่ได้ลองทำ WPS Client/Server แล้วก็ได้รับรู้ว่ามันมีจำกัด ด้าน Cross-Domain Request ซึ่งเป็นข้อจำกัดของความปลอดภัยก็พยายามหาข้อมูลอยู่นาน ก็เพิ่งมาเจอ ประเด็นหลักที่ รับทราบก็คือต้องทำ proxy server ในการติดต่อกับ web service อีกทีหนึ่งรายละเอียดจะรายงาน คืบหน้าครั้งต่อไปhttp://developer.yahoo.com/javascript/howto-proxy.htmlhttp://www.xml.com/pub/a/2005/11/09/fixing-ajax-xmlhttprequest-considered-harmful.html?page=last Powered by ScribeFire.]]></description>
				<content:encoded><![CDATA[<div xmlns='http://www.w3.org/1999/xhtml'>หลังจากที่ได้ลองทำ WPS Client/Server แล้วก็ได้รับรู้ว่ามันมีจำกัด ด้าน Cross-Domain Request ซึ่งเป็นข้อจำกัดของความปลอดภัย<br/><br/>ก็พยายามหาข้อมูลอยู่นาน ก็เพิ่งมาเจอ ประเด็นหลักที่ รับทราบก็คือต้องทำ proxy server ในการติดต่อกับ web service อีกทีหนึ่ง<br/><br/><img src='http://developer.yahoo.com/javascript/img/proxy3.gif'/><br/><br/><br/>รายละเอียดจะรายงาน คืบหน้าครั้งต่อไป<br/><br/>http://developer.yahoo.com/javascript/howto-proxy.html<br/><br/>http://www.xml.com/pub/a/2005/11/09/fixing-ajax-xmlhttprequest-considered-harmful.html?page=last<br/><br/><br/>
<p class='poweredbyperformancing'>Powered by <a href='http://scribefire.com/'>ScribeFire</a>.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>https://www.ninsawat.com/?feed=rss2&#038;p=29</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AJAX ปลีกย่อย</title>
		<link>https://www.ninsawat.com/?p=21&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ajax-%25e0%25b8%259b%25e0%25b8%25a5%25e0%25b8%25b5%25e0%25b8%2581%25e0%25b8%25a2%25e0%25b9%2588%25e0%25b8%25ad%25e0%25b8%25a2</link>
		<comments>https://www.ninsawat.com/?p=21#comments</comments>
		<pubDate>Thu, 14 Dec 2006 04:29:00 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[AJAX]]></category>

		<guid isPermaLink="false">http://www.ninsawat.com/?p=21</guid>
		<description><![CDATA[ตอนนี้ อะไร ๆ ๆ ก็คงต้อง AJAX (Asynchronous JavaScript and XML) นิยามที่ wikipedia แต่เวลา่ใช้งานจริงมักเกิดปัญหา เล็ก ๆ น้อย ๆ น่ารำคาญมาก เพราะสาเหตุดังนี้ - เป็น javascript ดู debug ยาก และยังเป็นติดต่อแบบเบื้องหลัง อีก แก้ปัญหาได้ใน Mozilla โดยใช้ Fire Bugข- ปัญหา cross platform ระหว่าง IE และ Mozilla เนื่องด้วยมันทำงานไม่เหมือกัน ทำให้เกิดหลากหลายเป็น นับตั้งแต่การสร้าง XHTMLRequest ซึ่งใน IE นั้นใช้เป็น ActiveX แล้วอีกทั้งการตอบการทำงานที่แตกต่างกัน การแก้ไขและรายละเอียดจะกล่าวข้างล่าง - อีกหัวข้อหลักแบบ โง่ ๆ ของ IE&#8230;]]></description>
				<content:encoded><![CDATA[<p>ตอนนี้ อะไร ๆ ๆ ก็คงต้อง AJAX (Asynchronous JavaScript and XML)  <a href="http://en.wikipedia.org/wiki/Ajax_%28programming%29">นิยามที่ wikipedia</a></p>
<p>แต่เวลา่ใช้งานจริงมักเกิดปัญหา เล็ก ๆ น้อย ๆ น่ารำคาญมาก เพราะสาเหตุดังนี้</p>
<p>- เป็น javascript ดู debug ยาก และยังเป็นติดต่อแบบเบื้องหลัง อีก แก้ปัญหาได้ใน Mozilla โดยใช้ Fire Bug<br />ข<br />- ปัญหา cross  platform ระหว่าง IE และ Mozilla เนื่องด้วยมันทำงานไม่เหมือกัน ทำให้เกิดหลากหลายเป็น นับตั้งแต่การสร้าง XHTMLRequest ซึ่งใน IE นั้นใช้เป็น ActiveX แล้วอีกทั้งการตอบการทำงานที่แตกต่างกัน การแก้ไขและรายละเอียดจะกล่าวข้างล่าง</p>
<p>- อีกหัวข้อหลักแบบ โง่ ๆ <span style="font-weight: bold;">ของ IE คือกระบวนการสร้าง XhtmlRequest นั้นต้องอยู่ Head tag </span>ตั้งแต่หัวของไฟล์ ซึ่ง Mozilla อยู่ไหนมันก็ตอบสนองทั้งสิ้น</p>
<p><span style="font-weight: bold;"> 1. ไฟล์ xmlhttp.js ให้ include ไว้สะตั้งแต่ head ไปเลย</span></p>
<blockquote><p><code><br />function createRequestObject() {</p>
<p>       var req;</p>
<p>       if(window.XMLHttpRequest){<br />           // Firefox, Safari, Opera...<br />           req = new XMLHttpRequest();<br />       } else if(window.ActiveXObject) {<br />           // Internet Explorer 5+<br />           req = new ActiveXObject("Microsoft.XMLHTTP");<br />       } else {<br />           // There is an error creating the object,<br />           // just as an old browser is being used.<br />           alert('There was a problem creating the XMLHttpRequest object');<br />       }</p>
<p>       return req;</p>
<p>}</p>
<p></code></p>
</blockquote>
<p><span style="font-weight: bold;">2. สร้าง XMLHTMLRequest เมื่อต้องการใช้งานและกำหนดค่าต่างๆ </span><br />ข้อสังเกต<br />- http.overrideMimeType(&#8220;text/xml&#8221;);  นั้นเป็นการกำหนดว่าข้อมูลที่ตอบรับกลับมานั้นเป็นรูปแบบใด แต่ใน IE นั้นไม่สนับสนุน XML จึงไม่ควรกำหนด แต่ต้องดำเนินการขั้นตอน ต่อไปหากต้องการรับข้อมูลแบบ XML<br />- strsub นั้นเป็นตัวแปลว่างเปล่า เพราะใน IE ไม่ให้ส่งแบบ http.send(null)<br />- บางครั้ง IE ไม่ยอมให้ใช้ http.onreadystatechange = PointReq; แต่ให้ใช้ http.onload แทนแต่ Mozilla นั้นยอมรับทั้งสองอย่าง</p>
<blockquote><p><code>
<p>// Make the XMLHttpRequest object<br />var http = createRequestObject();<br />var prog = "check.php";<br />var status_location = '';<br />var strsub ='';<br />function sendRequest() {<br />  var t1 = encodeURI(document.getElementById("address").value);<br />    // Open PHP script for requests<br />     http.onreadystatechange = PointReq;<br />      http.open('post',prog+"?address="+t1 ,true);<br />    // http.overrideMimeType("text/xml");     <br />http.send(strsub);  </p>
<p>}</p>
<p></code></p></blockquote>
<p><span style="font-weight: bold;">3.ตรวจรับผลของการเรียกใช้งาน</span><br />ข้อสังเกต</p>
<p>-จะเห็นว่า xmldoc นั้นมีการใช้รับค่าจาก Response ของ XMLHTMLRequest ที่แตกต่างกัน ตามที่ได้บอกไปแล้วว่าใน IE นั้นไม่ support .responseXML จึงต้องทำการสร้าง XMLDOC ขึ้นมาแล้วนำค่าใส่เข้าไปจาก .responseText แทน</p>
<p>-ใน IE นั้นควาย มากหากจะใช้ตัวแปลชื่อ status จงอย่าใช้ เพราะมันทำให้ผมติดเงก อยู่ 2 วัน</p>
<blockquote><p><code>
<p>function PointReq(){</p>
<p> if(http.readyState == 4 &&amp; http.status == 200 ){</p>
<p> if (document.implementation &&amp; document.implementation.createDocument){<br />  xmldoc = http.responseXML;<br /> //In case to be the internet explorer<br /> } else if (window.ActiveXObject){</p>
<p>  xmldoc = new ActiveXObject("Microsoft.XMLDOM");<br />  xmldoc.async = false;<br />  xmldoc.loadXML(http.responseText);<br /> }</p>
<p> root_node = xmldoc.getElementsByTagName("Result")[0];<br /> results = root_node.getAttribute("search");<br /> if(results == "Succeeded"){<br />  ......<br /> }<br />  else if (results =='Nomatch'){<br />         ......<br /> }<br />}<br />}</p>
<p></code></p></blockquote>
<p>ข้อมูลเพิ่มเติม อ้างอิงได้หลายที่ จากที่นี่ผมก้อเอามาครับ <a href="http://www.enja.org/david/?cat=14">Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>https://www.ninsawat.com/?feed=rss2&#038;p=21</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
