2

I am using ColdFusion 8 and jQuery 1.7.2.

I use a ton of ajax in my sites. Normally, I would use CFAJAXPROXY, but this has a limitation: It puts all values into the URL, which is limited to about 1250 characters. My data would exceed that (1,000 values of 4 digits each).

I do not usually submit whole forms at once. I usually submit small pieces of info as required, such as when a box is checked or unchecked. This works very well using CFAJAXPROXY. Now I need to submit one thousand (or more) checkboxes at the time and this throws a wrench in my system.

How can I submit this FORM as FORM POST without refreshing the entire page, like normal form posts do?

// I WANT TO REFRESH THIS DIV ON FORM SUBMISSION
<div>
<fieldset>
<form method='post' action='?' id='jsSaveAllManufacturersForm'>
<input type='button' value='Select All ' id='jsSelectAll'>
<input type='button' value='Deselect All ' id='jsDeselectAll'> 
<input type='button' value='Save Changes' id='jsSaveChanges'>
<input type='checkbox' value='1'> 1
<input type='checkbox' value='2'> 2
<input type='checkbox' value='3'> 3
</form> 
</fieldset>
<div>

// SET VARS 
var $SaveAllManufacturersForm = $('#jsSaveAllManufacturersForm'),
$SelectAll = $('#jsSelectAll'),
$DeselectAll = $('#jsDeselectAll'),
$SaveChanges = $("#jsSaveChanges");

// MY FUNCTION WHEN FORM IS SUBMITTED
var saveChanges = function(e) {
e.preventDefault();
$SaveAllManufacturersForm.submit();
    jroDash.saveAllManufacturers($SaveAllManufacturersForm);
}

// ACTION THAT LAUNCHES THE FORM SUBMISSION
$SaveChanges.click(saveChanges);
Evik James
  • 10,335
  • 18
  • 71
  • 122
  • 1
    Without really knowing anything about coldfusion, is there any reason you can't go straight to jQuery on the client-side and skip cfajaxproxy altogether? Here's a mention of somebody doing that to get around issues with cfajaxproxy not being able to handle large volumes of data (sounds similar to your issue in that regard) - http://www.davehking.com/2012/02/25/using-jquerys-json-parsing-instead-of-cfajaxproxys.html – Snixtor Feb 21 '13 at 21:02
  • CFAJAXPROXY actually saves a TON of time. There's a lot less coding involved to get stuff done. This is the first time in two years of using it that I have run into any issue with trying to pass excessive info. – Evik James Feb 21 '13 at 21:16
  • I would say that jQuery saves a ton of time too :) I can appreciate there may be subtle (or even very obvious) reasons why CFAJAXPROXY is a better choice in a coldfusion environment in *most* cases though. – Snixtor Feb 21 '13 at 21:24
  • 1
    Once you get used to using jQuery for posting data, CFAJAXPROXY does not save much time...if at all. CFAJAXPROXY also adds extra 'weight' to the page request that, as developers, we have absolutely no control over. – Scott Stroz Feb 21 '13 at 22:05
  • In the code above, I have a single line that submits the form values to the CFC (jroDash.saveAllManufacturers($SaveAllManufacturersForm);). Show the the jQuery code that is easier to read or less code. Please, show me. – Evik James Feb 21 '13 at 23:09
  • I don't measure saving time by how many lines of code it takes to perform a task. You could easily write that functionality in one line of code for jQuery. As much as I love ColdFusion, the AJAX/UI functionality is just dreadful, I have spoken out that it should all get ripped out, or sold/added as modules to the 'core'. Also...take a look at the minified source of jQuery. One. Single. Line. – Scott Stroz Feb 22 '13 at 04:30

1 Answers1

4

CFAJAXPROXY can easily be set to use POST instead of GET.

<cfajaxproxy cfc="CFCName" jsclassname="CFProxy"> 

<script>
    myProxy = new CFProxy();
    myProxy.setHTTPMethod('POST');
    myProxy.doMyAjaxMethod();
</script>`

http://forta.com/blog/index.cfm/2007/10/15/Using-POST-For-ColdFusion-Ajax-Calls

imthepitts
  • 1,647
  • 10
  • 9
  • Awesome! I can't wait to try it... Actually, I will have to wait till tomorrow. Thanks! – Evik James Feb 21 '13 at 23:06
  • Actually, no. I am not sure it's the wrong info; I just think our server has a security setting that disallows the post. So, I can't verify that it does or doesn't work (yet). I'll get he error for you in a minute. – Evik James Feb 25 '13 at 19:01
  • If you've applied this security hotfix to your server, then you'll need to change some settings to allow very large posts. [ColdFusion Post Parameters Limit Exceeded Exception](https://kb.edgewebhosting.net/KnowledgebaseArticle53448.aspx) – imthepitts Feb 25 '13 at 19:09