开发者

jQuery Ajax call with no results expected

开发者 https://www.devze.com 2022-12-16 23:06 出处:网络
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 scr

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.

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 exa开发者_JS百科ctly? Does jQuery support it? What about my php script, should it return a special HTTP header?

Any advice to make this efficient is welcomed.

Thanks

Nathan


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.

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

And the Status Code Definition sounds about right:

10.2.5 204 No Content

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消