Link Details

Link 197282 thumbnail
User 191976 avatar

By ganeshread
via gmarwaha.com
Published: Jun 28 2009 / 17:28

In modern web application development, many a times you would want to know if the incoming HTTP Request is an AJAX request or just a Normal request. Have you come across this requirement? I have, and the solution that I found turned out to be pretty straight-forward and I will be sharing it with you here.
  • 20
  • 1
  • 2113
  • 553

Comments

Add your comment
User 273087 avatar

Bob Schellink replied ago:

0 votes Vote down Vote up Reply

I don't think the X-Requested-With header is set for Ajax requests automatically. However JavaScript libraries such as jQuery, Prototype, Mootools etc do set this header so its probably a non issue unless you code Ajax by hand.

User 261337 avatar

John Rockefeller replied ago:

0 votes Vote down Vote up Reply

I also like the comments section which provides an alternate solution.

User 191976 avatar

Ganeshji Marwaha replied ago:

0 votes Vote down Vote up Reply

@sabob: Yes, you are right. I forgot to mention it in the post. Will update the post with necessary details.

User 2721 avatar

Johan Vos replied ago:

0 votes Vote down Vote up Reply

It is indeed very useful to detect whether a request comes from an Ajax call or from a plain html request.
This question is exactly something that can be answered using Jersey (JSR 311 refimpl) by using annotations (e.g. @Produces("application/json").
See my blog entry at http://blogs.lodgon.com/johan/Glassfish_REST_and_Jersey

User 395375 avatar

overtheline.myopenid.com replied ago:

0 votes Vote down Vote up Reply

&imajax=true

God

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.