jQuery Ajax調用沒有預期的結果

[英]jQuery Ajax call with no results expected


I'm trying to collect some stats on some clicking events happening on my webpage.

我正在嘗試收集一些關於我網頁上發生的點擊事件的統計數據。

I figured I would add an onmouse event to the links I want to track, and trigger an ajax call to my tracking php script.

我想我會在我想要跟蹤的鏈接上添加一個onmouse事件,並觸發對我的跟蹤php腳本的ajax調用。

What would be the most efficient way to do that, knowing that I don't expect anything in return, and that things should go on normally even if it fails?

什么是最有效的方法,知道我不期待任何回報,並且即使失敗,事情應該正常進行?

I know there are some special HTTP calls when you don't expect any data back. What is it exactly? Does jQuery support it? What about my php script, should it return a special HTTP header?

我知道當你不期待任何數據時,會有一些特殊的HTTP調用。究竟是什么? jQuery是否支持它?我的PHP腳本怎么樣,它應該返回一個特殊的HTTP頭?

Any advice to make this efficient is welcomed.

任何提高效率的建議都受到歡迎。

Thanks

謝謝

Nathan

彌敦道

1 个解决方案

#1


5  

You could send a 204 no content. Google seem to do it on their home page for exactly the same purpose for making the client look up a DNS entry faster.

您可以發送204無內容。谷歌似乎在他們的主頁上這樣做是為了讓客戶更快地查找DNS條目。

See this SO question about how Google uses it: Google.com and clients1.google.com/generate_204

請參閱此問題,了解Google如何使用它:Google.com和clients1.google.com/generate_204

And the Status Code Definition sounds about right:

狀態碼定義聽起來很正確:

10.2.5 204 No Content

10.2.5 204無內容

The server has fulfilled the request but does not need to return an entity-body, and might want to return updated metainformation. The response MAY include new or updated metainformation in the form of entity-headers, which if present SHOULD be associated with the requested variant.

服務器已完成請求但不需要返回實體主體,並且可能希望返回更新的元信息。響應可以包括實體標頭形式的新的或更新的元信息,如果存在,應該與所請求的變體相關聯。

If the client is a user agent, it SHOULD NOT change its document view from that which caused the request to be sent. This response is primarily intended to allow input for actions to take place without causing a change to the user agent's active document view, although any new or updated metainformation SHOULD be applied to the document currently in the user agent's active view.

如果客戶端是用戶代理,則它不應該從導致請求發送的文檔視圖中更改其文檔視圖。此響應主要用於允許在不導致更改用戶代理的活動文檔視圖的情況下進行操作的輸入,盡管任何新的或更新的元信息應該應用於當前在用戶代理的活動視圖中的文檔。

The 204 response MUST NOT include a message-body, and thus is always terminated by the first empty line after the header fields.

204響應絕不能包含消息體,因此總是在頭字段之后的第一個空行終止。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2010/01/14/725062cf46c0a1bb0733c90c8db9abba.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com