We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Ajax request problem

I have problem with the function isAjax(), it always return false even when i add the header "HTTP_X_REQUESTED_WITH" to "XMLHttpRequest", and when i print out the header info it is empty, too. I'm now using ubuntu 14.04 64bits, my code used to work well on ubuntu 12.04. Please help me.



check if there is no javascript/jQuery errors


I have checked the javascript code, i have also tried to send the request from a rest app with the setting of "HTTP_X_REQUESTED_WITH" in the header, but when printing out it is still empty.


After trying some value, i figure out that my function $request->getHeader('key') does not accept the 'key' which contains the special character. It can print out value if it was set with "HTTPXREQUESTEDWITH" (some other values which don't have any special character). Did i miss-configure something with the server ?

edited Sep '14

This problem do not related to the server or Phalcon at all.

I had exact same problem with AngularJS. You have to manually add the Header XMLHttpRequest After that in the $_SERVER variable will appear the key 'HTTP_X_REQUESTED_WITH' I assume that you are using JQuery

    url: 'foo/bar',
    headers: { 'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest' }

How can I add a custom HTTP header to ajax request with js or jQuery?

Also FYI some times there can be problems with Cross-Domain requests. Please see https://api.jquery.com/jquery.ajax/ crossDomain section of the manual. I do not say that it's related to your problem, but I just let you know about possible issues