Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts

    Question xhr - send data as string without a form?

    Hello, everyone.

    I'm attempting to send JSON data to a ColdFusion document that will process the data, but I'm hitting a brick wall.

    The data is too long to run as a GET. I've tried setting it up as a POST, but nothing is being submit to the .cfm file (nothing shows up in the form scope.)

    I'll try to type as much of the code as I can.

    Code:
    xhr = new XMLHttpRequest();
    xhr.open("POST","/path/to/document.cfm",false);
    xhr.setRequestHeader("Content-type","x-www-form-urlencoded");
    xhr.setRequestHeader("Content-length",JSON.stringify(finalarray).length + 9);
    xhr.setRequestHeader("Connection","close");
    xhr.send('thisData=' + JSON.stringify(finalarray));
    var reportText = xhr.responseText;
    Now, in the ColdFusion document all I'm doing is a CFDUMP (raw data dump) of the form scope. So, reportText should be that. But it's coming up blank. Empty. Nothing.

    How can I send a JSON string via xhr without using a form?

    Thank you,
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,189
    Thanks
    10
    Thanked 569 Times in 550 Posts
    Code:
    xhr.send('thisData=' + encodeURIComponent(JSON.stringify(finalarray)));
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  • #3
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Hi, rnd me. Thanks for the reply.

    Unfortunately, that didn't work, either.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #4
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    At least, it's not working for the ColdFusion FORM scope (where all POST data is sent, supposedly.)

    I've looked in FORM, URL, CLIENT, LOCAL, REQUEST, ARGUMENTS, ATTRIBUTES, and CLIENT scopes. The data just isn't there.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #5
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,189
    Thanks
    10
    Thanked 569 Times in 550 Posts
    Quote Originally Posted by WolfShade View Post
    At least, it's not working for the ColdFusion FORM scope (where all POST data is sent, supposedly.)

    I've looked in FORM, URL, CLIENT, LOCAL, REQUEST, ARGUMENTS, ATTRIBUTES, and CLIENT scopes. The data just isn't there.
    perhaps the content-length is being set wrong? it should be the number of bytes, not chars, which is complicated in JS when using any Unicode special sauce. Most servers reject over-runs and assume that uner-runs are still pending, even if the connection is closed. both those sisutations would likely prevent the data from being reachable by server-side code, except perhaps a debugger.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  • #6
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Okay.. then the most likely scenario is that I am incorrectly reporting the content length.

    Any suggestions on a solid JS way to calculate the content length?
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #7
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,189
    Thanks
    10
    Thanked 569 Times in 550 Posts
    Quote Originally Posted by WolfShade View Post
    Any suggestions on a solid JS way to calculate the content length?
    i didn't know of anything, but this seems to make sense:


    Code:
    s="hello ☚☛☄, how are you?"; //.length: 23
    
    unescape(escape(s).replace(/%u[a-f0-9]{4}/gi,"UU")).length // 26
    since 3 chars need 2 bytes, the result should be 3 more than mere char length. or at least that's my theory...

    EDIT: this is better:
    Code:
    encodeURI( str ).split(/%..|./).length - 1
    Last edited by rnd me; 05-13-2013 at 09:10 PM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  • #8
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Thanks, rnd me. I'll give that a shot and report back.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #9
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    I'm using the formula, but it's still not showing on the action page.

    There is one other possibility, that I'm still waiting for a response on a question posted in another forum. It's possible that the data being submit via AJaX to ColdFusion is NOT put into the FORM scope. Which would be odd, because whenever data is POSTed to ColdFusion, it's put into the FORM scope. But if something is preventing that, then my attempts may all be in vain.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #10
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,189
    Thanks
    10
    Thanked 569 Times in 550 Posts
    you can put it all in a hidden input and upload the form object itself, ever since ajax2...
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  • #11
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Except one of the things I haven't mentioned, yet, is that I'm calling this from a webWorker.. there is no body, document, or DOM, really.

    The .LDF file that I'm accessing LDAP data from is 1MB, currently. It can get bigger or smaller, but I figure it's worth going through a webWorker for.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •