最近接觸了jquery,感覺很不錯,以后不用寫這么繁雜的js代碼了,不錯,現在手上又接了個新項目,正好在新項目上邊學邊用了,此文繼續更新中...
Ajax也用了很長時間了,今天只是想整理一下我心中的Ajax.
簡單的說Ajax就是實現了異步向服務器請求數據,讓用戶有更好的體驗.
XMLHttpRequest其實也就只有兩種方式返回請求后的數據:
1.responseText方式,它是返回文本字串的方式,其實采用這種方式,通常是在服務端在對請求響應處理后,生成好要在瀏覽器上展示的html代碼后,再直接輸出到客戶端,更新需要更新的客戶端頁面內容.這種方式的好處是能在服務端生成好客戶端代碼,可減輕客戶端的負擔,客戶端只需將服務端生成的代碼innerHTML到對應的區域就行了... ... 但它的缺點在于,輸出到客戶端的是文本數據,所以無法對得到的數據在客戶端進行處理,所以就難以行成根據取回的數據的差異對頁面進行必要的邏輯處理.
2.responseXML方式,它是返回XML格式的文本,它是在服務端在對請求響應處理后,將數據以XML格式的文本返回到客戶瀏覽器上,然后再由客戶端來完成方式1中由服務端來完成的生成頁面展示的內容. 客戶端將解析返回的XML數據,然后再進行頁面的展示,由于是XML數據所以可以進行解析便可以根據解析出的數據對如何展示頁面進行邏輯處理,在這一點上是比responseText要靈活的.但付出的是加大了客戶端的負擔.
其實現在我正在學習JSON,如果在responseText方式中返回JSON方式的數據的話,是完全可以讓responseText和responseXML一樣的靈活的,因為JSON也是一種數據結構,可以將要返回的數據組織在其中,到客戶端再進行解析,解析也相當簡單,只需evel執行即可... 但前提是輸出到客戶端的JSON數據結構是正確的,不然js就會bomb!
以上是僅是我個人的看法,有不對之處請大家多指點!
<IMG onclick="go()" ID="sphere" SRC="tt.jpg" STYLE="position:absolute;filter:fliph;clip=rect(100 170 140 70)"/>
這樣以后,無法響應onclick事件,試了其它事件,好像都不能響應了,
如果改成:
<IMG onclick="go()" ID="sphere" SRC="tt.jpg" STYLE="position:absolute;clip=rect(100 170 140 70)"/>
或
<IMG onclick="go()" ID="sphere" SRC="tt.jpg" STYLE="position:absolute;filter:fliph"/>
就都能響應事件
請問這是為什么啊,就想知道為什么?
以下是近期項目碰到的ajax的一些問題列舉出來供大家分享,希望有所幫助,還在不斷增加中:
1.ajax,action中response返回的xml文檔格式錯誤時,eclipse debug進入不到action中.
2.ajax緩存問題,需要加入xmlHttp.setRequestHeader("If-Modified-Since","0");便可解決.
3.如果不是ajax提交,而設置了PrintWriter out = response.getWriter();則jsp會產生中文亂碼.
4.ajax返回xml亂碼的原因
response.setContentType("text/xml;charset=GBK");
PrintWriter out = response.getWriter();
這樣才起作用,如果這樣:
PrintWriter out = response.getWriter();
response.setContentType("text/xml;charset=GBK");
那么response.setContentType("text/xml;charset=GBK");就不起作用了所以返回是亂碼,這個問題搞了很久,代碼還得仔細看啊.
5.ajax表單提交
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
由于傳過去的是utf-8編碼的,所以在action 或servlet中接受時要進行相應轉碼.
我用的是webwork最新版本2.2,,
在頁面上輸入姓名后提交到helloWorld.action,到一個新的頁面,可interceptor不起作用,所以早前輸入的name值也為null.
可不知為什么interceptor不起作用,請大家幫幫忙,這個問題困擾我一個星期了..還是沒能解決..
Tomcat不報錯,但顯示如下信息:
請各位大俠幫幫忙啊,小弟先謝了...
2005-12-5 17:13:32 com.opensymphony.xwork.config.providers.XmlConfigurationProvider verifyInterceptor
嚴重: Unable to load class com.opensymphony.xwork.spring.interceptor.ActionAutowiringInterceptor for interceptor name au
towiring. This interceptor will not be available.
Cause: Could not load class com.opensymphony.xwork.spring.interceptor.ActionAutowiringInterceptor. Perhaps it exists but
certain dependencies are not available?
2005-12-5 17:13:32 com.opensymphony.xwork.config.providers.InterceptorBuilder constructInterceptorReference
嚴重: Unable to find interceptor class referenced by ref-name completeStack
我的xwork.xml內容如下:
<xwork>
<include file="webwork-default.xml"/>
<package name="default" extends="webwork-default">
<!-- Include webwork defaults (from WebWork JAR). -->
<default-interceptor-ref name="completeStack"/>
<action name="helloWorld"
class="test.HelloWorldAction">
<result name="success">hello.jsp</result>
<result name="input">name.jsp</result>
</action>
</package>
</xwork>
I have been browsing website of the Apache Software Foundation the whole day.
The Apache Software Foundation is an opensource organization of java, and it has many projects and subprojects, such as Tomcat,Struts,Logging,Web Service and Httpclient.
This organization has many volunteers from all over the world, they contribute their achievements to this organization.
The orgznization has developed rapidly.
I thouht how I can share my achievements with them?
I know now.
The organization has a community on it's website.
I thought I can learned a lot of knowledge of java here. 