Is Ajax called this method?

2019-07-15 12:37发布

I have created one web service that will may called from web using jQuery ajax call or may call from desktop application that I have created
I want to know in that webservice method.. Is this ajax call or not?..

Is that possible?

2条回答
唯我独甜
2楼-- · 2019-07-15 13:23

If the HTTP_X_REQUESTED_WITH server variable is set and equals to 'XMLHttpRequest', you can assume that the request was made via jQuery AJAX.

查看更多
成全新的幸福
3楼-- · 2019-07-15 13:23

As @Tatu Ulmanen answered you can check the HTTP_X_REQUESTED_WITH server variable is set and equals to 'XMLHttpRequest' to know that the request is ajax.

For this to work it is important that the correct header is set by you or the javascript library you are using. Otherwise there is no way to differentiate because ajax requests are normal GET or POST requests

查看更多
登录 后发表回答