2008年12月23日

Setting the HTTP charset parameter

因為太常用到了





所以轉貼至我的網誌





方便日後查詢





以下節錄自:


http://www.w3.org/International/O-HTTP-charset





只紀錄Code部份










<h2>Scripting the header</h2>

The appropriate header can also be set in server side scripting languages. For example:



Perl. Output the correct header before any part of the actual page. After the last header, use a double linebreak, e.g.:


print "Content-Type: text/html; charset=utf-8\n\n";



Python. Use the same solution as for Perl (except that you don't need a semicolon at the end).



PHP. Use the header() function before generating any content, e.g.:


header('Content-type: text/html; charset=utf-8');



Java Servlets. Use the setContentType method on the ServletResponse before obtaining any object (Stream or Writer) used for output, e.g.:


resource.setContentType ("text/html;charset=utf-8");


If you use a Writer, the Servlet automatically takes care of the conversion from Java Strings to the encoding selected.



JSP. Use the page directive e.g.:


<%@ page contentType="text/html; charset=UTF-8" %>


Output from out.println() or the expression elements (<%= object%>) is automatically converted to the encoding selected. Also, the page itself is interpreted as being in this encoding.



ASP and ASP.Net. content type and charset are set independently, and are methods on the response object. To set the charset, use e.g.:


<%Response.charset="utf-8"%>


In ASP.Net, setting Response.ContentEncoding will take care both of the charset parameter in the HTTP Content-Type as well as of the actual encoding of the document sent out (which of course have to be the same). The default can be set in the globalization element in Web.config (or Machine.config, which is originally set to UTF-8).



2008年12月1日

【ExtJS】Ajax Communication failure 解決方法

只需在Ajax failure function 內加入







failure: function(obj1,obj2) {



               if(obj1.statusText == 'communication failure') {



                    var task = new Ext.util.DelayedTask(/*你的ajax code or function*/);



                    task.delay(1);



                }else{



                    alert('請告知管理員伺服器有 : '+obj1.statusText+' 的錯誤');



                }



}



或檢查呼叫的php有無不會顯示訊息的執行錯誤

例如:無限遞迴