How do I check if the request is made via AJAX in CodeIgniter?

前端 未结 7 2038
余生分开走
余生分开走 2020-11-28 08:29

How do I check if the request is an AJAX? I am using CodeIgniter. I have a link that when it clicked, it\'ll open the pop-up dialog window this is done through ajax it reque

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 09:12

    If you are using a library that sends the X-Requested-With header, then you can do...

    if (strtolower(filter_input(INPUT_SERVER, 'HTTP_X_REQUESTED_WITH')) === 'xmlhttprequest') {
       // I'm AJAX!
    }
    

提交回复
热议问题