简体   繁体   English

通过AJAX提交表单输入更改的Coldbox RC范围并返回字符串以显示在页面上

[英]Submitting Coldbox RC scope on form input change via AJAX and returning string to display on page

I need to pass in form variables via AJAX every time a select box value is changed, and get a returned string from the AJAX call to display on the page. 每次更改选择框值时,我都需要通过AJAX传递表单变量,并从AJAX调用获取返回的字符串以显示在页面上。 Here's the situation: 情况如下:

I built a form which is dynamically built by the user for a set of compliance rules. 我构建了一个表单,该表单是由用户为一组合规性规则动态构建的。 This allows the user to have multiple select boxes to generate a logic statement such as the following: 这使用户可以有多个选择框来生成如下逻辑语句:

(
  ( 6779 AND 10852 AND 10845 )
  AND 
  (
    ( 8260 AND 8258 ) 
  )
)
OR
( 6780 OR 10845 OR 8258 OR 12893 )

I've written a function that returns this logic statement as a string after submission of the form, but would like to dynamically populate a div (#logicblock) on the form page BEFORE submitting, so that the user can verify the logic before submission of the information into our database. 我编写了一个函数,该函数在提交表单后以字符串形式返回此逻辑语句,但是想在提交之前在表单页面上动态填充div(#logicblock),以便用户可以在提交表单之前验证逻辑信息进入我们的数据库。

I tried to use the following: 我尝试使用以下内容:

 ('##logicblock').load("#getmodel('model.compliance').BuildLogic(rc)#", function(response){
     $('##logicblock').html(response);
 })

... but this does not properly pass in the RC scope into my model. ...但这无法将RC范围正确地传递到我的模型中。 I've searched and can't find a way that makes sense to me to send the entire form scope into a method that returns a value for display on the page. 我进行了搜索,找不到一种对我有意义的方法,该方法可以将整个表单范围发送到一种返回值以显示在页面上的方法中。

I got it figured out. 我明白了。 Because the form fields are dynamically generated, I found that I couldn't use a $('select').change() event to call the method, so I wrote a handler method to generate the data and serialized the form to pass in to the handler. 因为表单字段是动态生成的,所以我发现我无法使用$('select').change()事件来调用该方法,因此我编写了一个处理程序方法来生成数据并序列化表单以传递给处理者。 I was able to use the following to get the desired response: 我能够使用以下命令获得所需的响应:

function updateLogicBlock(){
    var serialform = $('form').serialize();
    $.get("#event.buildLink('handler.buildComplianceLogic')#?" + serialform, 
      function(data) {
        $('##logicblock').html(data);
    });
};

Then I simply added onChange="updateLogicBlock();" 然后我简单地添加了onChange="updateLogicBlock();" to every select box on the form. 到表单上的每个选择框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM