isAjax() function broken in 1.2 preview #99

Closed
chapmandu opened this Issue Oct 16, 2012 · 25 comments

Projects

None yet

3 participants

@chapmandu
CFWheels member

It seems that the request.cgi.http_x_requested_with variable is empty in a request made via ajax, when it should be "XMLHTTPRequest".

This causes the isAjax() function to return false for ajax requests, which in turn displays the CFWheels debug output.

Railo 3.2.0

@rip747

what webserver are you using? also, can you post a dump of the headers that are reported when you do an ajax request? You can do that using something like firebug or the dev tools in chrome, ie9

@chapmandu
CFWheels member

Railo 3.2.3.000
Apache Tomcat Version 6.0.32

Response Headers

Content-Length 65728
Content-Type text/html;charset=UTF-8
Date Thu, 01 Nov 2012 20:12:14 GMT
Railo-Version 3.2.3.000
Server Apache-Coyote/1.1

Request Headers

Accept /
Accept-Encoding gzip, deflate
Accept-Language en-us,en;q=0.5
Connection keep-alive
Cookie CFID=3ba018e4-cd6b-45a1-ac6d-b4d7a4cfd7fc; CFTOKEN=0
Host localhost:8888
Referer http://localhost:8888/myapp/index.cfm?controller=dashboard&action=index
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2
X-Requested-With XMLHttpRequest

isAjax (cfdump)

boolean false

request.cgi (cfdump)

content_type

http_accept /
http_host localhost:8888
http_referer http://localhost:8888/myapp/index.cfm?controller=dashboard&action=index
http_x_original_url

http_x_requested_with

http_x_rewrite_url

path_info

query_string controller=dashboard&action=status-content
redirect_url

remote_addr 127.0.0.1
request_method POST
request_uri

script_name /myapp/index.cfm
server_name localhost
server_port 8888
server_port_secure 0
server_protocol HTTP/1.1

ajax call (jQuery 1.7.1)

$.ajax({
type: "POST"
,url: "/myapp/index.cfm?controller=dashboard&action=status-content"
,success: function(response) {
$("#abc").html(response);
}
});

@rip747

that is weird, this could be a tomcat bug. if you look at the reported headers being passed to the browser:

X-Requested-With XMLHttpRequest

however, http_x_requested_with is being reported to Railo as blank from Tomcat

@rip747

what webserver are you using? is this railo express?

@rip747

also, make sure that you aren't accidentally redirecting the person and as thus losing the original header. if you are using url redirect, disable it and see if the problem still exists.

@chapmandu
CFWheels member

It is railo express. There are no redirects.

@rip747

I'm thinking this is more a railo express issue then a wheels issue. I created a simple template and executed it and the version of railo express that i have doesn't even have a http_x_requested_with header in it:

CGI Scope [Entries:46]
x2auth_password string
x2auth_type string
x2auth_user string
x2cert_cookie string
x2cert_flags string
x2cert_issuer string
x2cert_keysize string
x2cert_secretkeysize string
x2cert_serialnumber string
x2cert_server_issuer string
x2cert_server_subject string
x2cert_subject string
x2cf_template_path string W:\Inetpub\wwwroot\cfwheels\a\b\index.cfm
x2content_length string 9
x2content_type string application/x-www-form-urlencoded; charset=UTF-8
x2context_path string
x2gateway_interface string
x2http_accept string */*
x2http_accept_encoding string gzip,deflate,sdch
x2http_accept_language string en-US,en;q=0.8
x2http_connection string keep-alive
x2http_cookie string
x2http_host string 127.0.0.1:8888
x2http_referer string http://127.0.0.1:8888/
x2http_user_agent string Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4
x2https string
x2https_keysize string
x2https_secretkeysize string
x2https_server_issuer string
x2https_server_subject string
x2local_addr string 10.230.124.101
x2local_host string a059464
x2path_info string
x2path_translated string W:\Inetpub\wwwroot\cfwheels\a\b\index.cfm
x2query_string string
x2remote_addr string 127.0.0.1
x2remote_host string 127.0.0.1
x2remote_user string
x2request_method string POST
x2script_name string /index.cfm
x2server_name string 127.0.0.1
x2server_port string 8888
x2server_port_secure string 0
x2server_protocol string HTTP/1.1
x2server_software string
x2web_server_api string

Try executing the following template on your railo express version and post here what the response is:

<cfif !StructIsEmpty(form)>

    <cfdump var="#cgi#" format="text">
    <cfabort>

</cfif>

<html>
<head>
    <script src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
    <script>
    $(function(){

        $("#ajaxtest").on("click", function(){

        $.ajax({ 
            type: "POST"
            ,url: "index.cfm"
            ,data: {name: 'tony'}
            ,success: function(response) { 
                $("#response").html(response);
            } 
        });

        });

    });
    </script>
</head>
<body>
<p><a href="#" id="ajaxtest">Ajax test</a></p>
<div id="response"></div>
</body>
</html>

I'm thinking that you actually have to use a webserver in front of tomcat/jetty in order to get that header value.

@chapmandu
CFWheels member

I will post the results in the next few days.

The odd thing is that 1.1.8 works perfectly using the same code, its only when I run it with the 1.2 beta that isajax() returns false.

@rip747
@chapmandu
CFWheels member

Here is the response to the test above:

CGI Scope
Entries:46
auth_password string

auth_type string

auth_user string

cert_cookie string

cert_flags string

cert_issuer string

cert_keysize string

cert_secretkeysize string

cert_serialnumber string

cert_server_issuer string

cert_server_subject string

cert_subject string

cf_template_path string C:\railo\tomcat\webapps\ROOT\myapp\index.cfm

content_length string 9

content_type string application/x-www-form-urlencoded; charset=UTF-8

context_path string

gateway_interface string

http_accept string /

http_accept_encoding string gzip, deflate

http_accept_language string en-us,en;q=0.5

http_connection string keep-alive

http_cookie string CFID=3ba018e4-cd6b-45a1-ac6d-b4d7a4cfd7fc; CFTOKEN=0

http_host string localhost:8888

http_referer string http://localhost:8888/myapp/index.cfm

http_user_agent string Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2

https string

https_keysize string

https_secretkeysize string

https_server_issuer string

https_server_subject string

local_addr string 127.0.0.1

local_host string AngelOfDeath

path_info string

path_translated string C:\railo\tomcat\webapps\ROOT\myapp\index.cfm

query_string string

remote_addr string 127.0.0.1

remote_host string 127.0.0.1

remote_user string

request_method string POST

script_name string /myapp/index.cfm

server_name string localhost

server_port string 8888

server_port_secure string 0

server_protocol string HTTP/1.1

server_software string

web_server_api string

@rip747

ok. seems you're getting the same data as i am. was you're output using 1.2 beta or 1.1.8? I would like to see the output for 1.1.8. it would be weird if the output was different.

@chapmandu
CFWheels member

The previous CGI dump was from 1.1.8. Below is 1.2beta

CGI Scope
Entries:46
auth_password string

auth_type string

auth_user string

cert_cookie string

cert_flags string

cert_issuer string

cert_keysize string

cert_secretkeysize string

cert_serialnumber string

cert_server_issuer string

cert_server_subject string

cert_subject string

cf_template_path string C:\railo\tomcat\webapps\ROOT\myapp\index.cfm

content_length string 9

content_type string application/x-www-form-urlencoded; charset=UTF-8

context_path string

gateway_interface string

http_accept string /

http_accept_encoding string gzip, deflate

http_accept_language string en-us,en;q=0.5

http_connection string keep-alive

http_cookie string CFID=3ba018e4-cd6b-45a1-ac6d-b4d7a4cfd7fc; CFTOKEN=0

http_host string localhost:8888

http_referer string http://localhost:8888/myapp/index.cfm

http_user_agent string Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2

https string

https_keysize string

https_secretkeysize string

https_server_issuer string

https_server_subject string

local_addr string 127.0.0.1

local_host string AngelOfDeath

path_info string

path_translated string C:\railo\tomcat\webapps\ROOT\myapp\index.cfm

query_string string

remote_addr string 127.0.0.1

remote_host string 127.0.0.1

remote_user string

request_method string POST

script_name string /myapp/index.cfm

server_name string localhost

server_port string 8888

server_port_secure string 0

server_protocol string HTTP/1.1

server_software string

web_server_api string

@rip747

awesome, i'll try to look into this issue over the weekend.

@rip747

looking into this now and honestly, i cannot find a difference between the 1.1.8 code and 1.2.0 code that would affect the isAjax() not working. let's try a different approach. Could you take your 1.1.8 and 1.2.0 apps and dump and the REQUEST.CGI scope in each app?

@chapmandu
CFWheels member

Railo 3.3.4.003

1.2 preview 2

Struct [Entries:18]
x1content_type string
x1http_accept string /
x1http_host string localhost:8888
x1http_referer string http://localhost:8888/myapp/index.cfm?controller=dashboard&action=index
x1http_x_original_url string
x1http_x_requested_with string
x1http_x_rewrite_url string
x1path_info string
x1query_string string controller=dashboard&action=task-content&span=0,0
x1redirect_url string
x1remote_addr string 127.0.0.1
x1request_method string GET
x1request_uri string
x1script_name string /valkyrie/index.cfm
x1server_name string localhost
x1server_port string 8888
x1server_port_secure string 0
x1server_protocol string HTTP/1.1

1.1.8

Struct [Entries:14]
x1content_type string
x1http_accept string /
x1http_host string localhost:8888
x1http_referer string http://localhost:8888/myapp/index.cfm?controller=dashboard&action=index
x1http_x_requested_with string XMLHttpRequest
x1path_info string
x1query_string string controller=dashboard&action=task-content&span=0,0
x1remote_addr string 127.0.0.1
x1request_method string GET
x1script_name string /valkyrie/index.cfm
x1server_name string localhost
x1server_port string 8888
x1server_port_secure string 0
x1server_protocol string HTTP/1.1

@rip747

thank you so much for getting me that info. that is really strange how it is doing that. ok, the first thing we need to do is see if it is the method itself that that is causing the error. try commenting the $cgiscope method in 1.2.0 and copying the $cgiscope method from 1.1.8. let's see if we get the same values at that point.

@chapmandu
CFWheels member

Looks like the problem is related to the 1.2 $cgiscope method.

Copying the 1.1.8 method into 1.2 returned the correct request.cgi variables for isajax() to work correctly.

However, it's still puzzling how it works correctly in 1.1.8 even though it appears that the http_x_requested_with variable doesn't exist in cgi scope.

@rip747

awesome! ok one more thing. put back the original 1.2.0 $cgiscope method. now replace the following lines in that method:

        var loc = {};
        loc.returnValue = {};
        loc.iEnd = ListLen(arguments.keys);
        for (loc.i=1; loc.i <= loc.iEnd; loc.i++)
        {
            loc.key = ListGetAt(arguments.keys, loc.i);
            loc.returnValue[loc.key] = "";
            if (StructKeyExists(arguments.scope, loc.key))
            {
                loc.returnValue[loc.key] = arguments.scope[loc.key];
            }
        }

with this:

        var loc = {};
        loc.returnValue = {};
        loc.iEnd = ListLen(arguments.keys);
        for (loc.i=1; loc.i <= loc.iEnd; loc.i++)
            loc.returnValue[ListGetAt(arguments.keys, loc.i)] = cgi[ListGetAt(arguments.keys, loc.i)];

basically were just replacing the top portion of the 1.2.0 $cgiscope method with the one from 1.1.8. I want to leave the fix for urlrewriting in there.

@rip747

whoops!!! screwed up that last piece of code. use this:

        var loc = {};
        loc.returnValue = {};
        loc.iEnd = ListLen(arguments.keys);
        for (loc.i=1; loc.i <= loc.iEnd; loc.i++)
            loc.returnValue[ListGetAt(arguments.keys, loc.i)] = arguments.scope[ListGetAt(arguments.keys, loc.i)
@rip747

my whole thing is I'm thinking that maybe the http_x_requested_with key in the cgi struct gets set later or something.

@chapmandu
CFWheels member

Using this code fixes the issue. Just had to close square brackets.


var loc = {};
loc.returnValue = {};
loc.iEnd = ListLen(arguments.keys);
for (loc.i=1; loc.i <= loc.iEnd; loc.i++)
loc.returnValue[ListGetAt(arguments.keys, loc.i)] = arguments.scope[ListGetAt(arguments.keys, loc.i)];

@rip747

Excellent! I'll put it in tonight

@rip747

sorry about this, but can you test out this piece of code. i'm concerned that maybe the passed in scope might not contain all the keys that wheels looks for:

        var loc = {};
        loc.returnValue = {};
        loc.iEnd = ListLen(arguments.keys);

        for (loc.i=1; loc.i <= loc.iEnd; loc.i++)
        {
            loc.returnValue[ListGetAt(arguments.keys, loc.i)] = "";
        }

        StructAppend(loc.returnValue, arguments.scope, true);
@chapmandu
CFWheels member

I tested the code above and it breaks isAjax()

Here is a dump of the $cgiscope loc.returnValue

Struct [Entries:51]
x5yauth_password string
x5yauth_type string
x5yauth_user string
x5ycert_cookie string
x5ycert_flags string
x5ycert_issuer string
x5ycert_keysize string
x5ycert_secretkeysize string
x5ycert_serialnumber string
x5ycert_server_issuer string
x5ycert_server_subject string
x5ycert_subject string
x5ycf_template_path string C:\railo\tomcat\webapps\ROOT\myapp\index.cfm
x5ycontent_length string
x5ycontent_type string
x5ycontext_path string
x5ygateway_interface string
x5yhttp_accept string /
x5yhttp_accept_encoding string gzip, deflate
x5yhttp_accept_language string en-us,en;q=0.5
x5yhttp_connection string keep-alive
x5yhttp_cookie string CFID=3ba018e4-cd6b-45a1-ac6d-b4d7a4cfd7fc; CFTOKEN=0; RAILO_ADMIN_LANG=en; RAILO_ADMIN_LASTPAGE=services.datasource; flash={}; JSESSIONID=59C13D5069F9B50F49DAA68F8E076A15
x5yhttp_host string localhost:8888
x5yhttp_referer string http://localhost:8888/myapp/index.cfm?controller=dashboard&action=index
x5yhttp_user_agent string Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2
x5yhttp_x_original_url string
x5yhttp_x_requested_with string
x5yhttp_x_rewrite_url string
x5yhttps string
x5yhttps_keysize string
x5yhttps_secretkeysize string
x5yhttps_server_issuer string
x5yhttps_server_subject string
x5ylocal_addr string 192.168.43.250
x5ylocal_host string AngelOfDeath
x5ypath_info string
x5ypath_translated string C:\railo\tomcat\webapps\ROOT\myapp\index.cfm
x5yquery_string string controller=dashboard&action=task-content&span=0,0
x5yredirect_url string
x5yremote_addr string 127.0.0.1
x5yremote_host string 127.0.0.1
x5yremote_user string
x5yrequest_method string GET
x5yrequest_uri string
x5yscript_name string /myapp/index.cfm
x5yserver_name string localhost
x5yserver_port string 8888
x5yserver_port_secure string 0
x5yserver_protocol string HTTP/1.1
x5yserver_software string
x5yweb_server_api string

@rip747 rip747 was assigned Dec 13, 2012
@rip747

fixed 1921409

@rip747 rip747 closed this Dec 13, 2012
@perdjurner perdjurner modified the milestone: 1.3.0, 1.2.0 Jul 16, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment