Coldfusion保存变量而无需转到另一页

时间:2015-10-05 13:46:50

标签: jquery coldfusion

我正在尝试编写一个基本上只有一页但在该页面上有许多功能的程序。我的问题是如果变量总是在同一页面上,我如何保存变量。我尝试使用bootstrap来解决一些问题,但我不确定如何保存ColdFusion变量并返回同一页面。

在此示例中,它显示了始终处于启动状态的主页面。当您单击打印标签时,会弹出一个引导程序问题,询问他们希望从哪个数字开始打印标签。如何在coldfusion中接受保存该变量?

因为真的接受按钮关闭了引导程序,但它不像我要离开这个页面去另一个来保存会话变量或任何东西。这个页面上的所有按钮基本上都会做类似的事情。就像你点击新按钮一样。那么如何在不转到其他页面的情况下保存变量呢?我是否尝试以某种方式保存变量来刷新页面?只是不确定,因为页面永远不会转到另一页。

我试过了:

$(document).ready(function(){
    // What happens when a user hits the "Accept" button on the dealer form
    $(".label_accept").click(function(){
        $('#LabelMaker').modal('hide');

        var LabelNum =

            $.ajax({
                // the location of the CFC to run
                  url: "example_cf7_proxy.cfm"
                // send a GET HTTP operation
                , type: "get"
                // tell jQuery we're getting JSON back
                , dataType: "json"
                // send the data to the CFC
                , data: {
                    // send the ID entered by the user
                     LabelNum: $("#LabelNum").val()
                }
                // this gets the data returned on success
                , success: function (data){
                    // this uses the "jquery.field.min.js" library to easily populate your form with the data from the server
                    $("#dealerForm").formHash(data);
                }
                // this runs if an error
                , error: function (xhr, textStatus, errorThrown){
                    // show error
                    console.log(errorThrown);
                }
            });

    });

});

example_cf7_proxy.cfm

<!---// this acts as a proxy to our CFC //--->
<cfinvoke
    component="example"
    method="#url.method#"
    argumentCollection="#url#"
    returnVariable="results"
        />

<!---// convert the results to JSON using the CFJSON component //--->
<cfset json = createObject("component", "cfjson") />

<cfcontent reset="true" /><cfoutput>#json.encode(results, false)#</cfoutput>

但我收到此错误: SyntaxError:JSON.parse:JSON数据的第1行第1列意外的数据结尾

http://jsfiddle.net/1zka4soy/3/

JS

$(document).ready(function(){
    // What happens when a user hits the "Accept" button on the dealer form
    $(".label_accept").click(function(){
        $('#LabelMaker').modal('hide');

    });

});

$(document).ready(function(){
    // What happens when a user hits the "Accept" button on the dealer form
    $(".dealer_accept").click(function(){
        $('#NewDealer').modal('hide');

    });

});

HTML

<form id="dealerForm">
    <div class="container">
        <div class="row">
            <div class="col-xs-6">
                <div class="row">
                    <div class="col-xs-8">
                        <label for="ItemID">ITEM ID</label>
                        <div class="input-group">
                            <input type="text" class="form-control" name="ItemID" id="ItemID"> <span class="input-group-btn">
                            <input class="btn btn-default" type="button" name="Search" id="Search" value="SEARCH"/>
                            </span>

                        </div>
                    </div>
                    <div class="col-xs-4">
                        <label for="Qty">QTY</label>
                        <select name="Qty" id="Qty" class="form-control">
                            <option value="1" selected>1</option>
                            <option value="2">2</option>
                            <option value="3">3</option>
                            <option value="4">4</option>
                            <option value="5">5</option>
                            <option value="6">6</option>
                            <option value="7">7</option>
                            <option value="8">8</option>
                            <option value="9">9</option>
                            <option value="10">10</option>
                            <option value="11">11</option>
                            <option value="12">12</option>
                            <option value="13">13</option>
                            <option value="14">14</option>
                            <option value="15">15</option>
                            <option value="16">16</option>
                            <option value="17">17</option>
                            <option value="18">18</option>
                            <option value="19">19</option>
                            <option value="20">20</option>
                        </select>
                    </div>
                    <div class="col-xs-12">
                        <label for="Dealers"></label>
                        <div class="input-group">
                            <select name="Dealers" id="Dealers" class="form-control">
                                <option value="" selected></option>
                                <option value="1">1</option>
                            </select> <span class="input-group-btn">
                            <input class="btn btn-default" type="button"  name="New" value="NEW" data-toggle="modal" data-target="#NewDealer"/>
                            </span>

                        </div>
                    </div>
                    <div class="col-xs-12">
                        <label for="table"></label>
                        <table class="table table-hover">
                            <tr>
                                <td>Jill</td>
                                <td>Smith</td>
                                <td>50</td>
                            </tr>
                            <tr>
                                <td>Eve</td>
                                <td>Jackson</td>
                                <td>94</td>
                            </tr>
                            <tr>
                                <td>Jill</td>
                                <td>Smith</td>
                                <td>50</td>
                            </tr>
                            <tr>
                                <td>Eve</td>
                                <td>Jackson</td>
                                <td>94</td>
                            </tr>
                            <tr>
                                <td>Jill</td>
                                <td>Smith</td>
                                <td>50</td>
                            </tr>
                            <tr>
                                <td>Eve</td>
                                <td>Jackson</td>
                                <td>94</td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
            <div class="col-xs-6">
                <div class="row">
                    <div class="col-xs-12">
                        <label class="centered" for="DueToday">DUE TODAY @ 5:00 (10/1/15)</label>
                        <textarea class="form-control" rows="7"></textarea>
                    </div>
                    <div class="col-xs-12">
                        <label class="centered" for="DueToday">DUE 10/02/15 @ 5:00</label>
                        <textarea class="form-control" rows="7"></textarea>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="row">
                    <div class="col-xs-12">
                    <label for="Buttons"></label>
                        <div class="btn-group btn-group-justified" role="group" aria-label="...">
                            <div class="btn-group" role="group">
                                <input class="btn btn-default" type="button" name="Report" value="REPORT">
                            </div>
                            <div class="btn-group" role="group">
                                <button type="button" class="btn btn-default" data-toggle="modal" data-target="#LabelMaker">PRINT LABELS</button>
                            </div>
                            <div class="btn-group" role="group">
                                <input class="btn btn-default" type="button" name="LogItIn" value="LOG IT IN">
                            </div>
                            <div class="btn-group" role="group">
                                <input class="btn btn-default" type="button" name="CompleteIt" value="COMPLETE IT">
                            </div>
                            <div class="btn-group" role="group" id="ExitBtn" style="display:none">
                                <input class="btn btn-default" type="button" name="Exit" id="Exit" value="EXIT">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

<!-- Label Maker Modal -->
<div class="modal fade" id="LabelMaker" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title" id="myModalLabel">Label Maker</h4>
      </div>
      <div class="modal-body">

        <div class="row">
            <div class="col-xs-12">
                <label for="LabelNum">Please enter label start number:</label>
                <div class="input-group">
                <input type="text" class="form-control" name="LabelNum" id="LabelNum">
                </div>
            </div>
        </div>


      </div>
      <div class="modal-footer group">
        <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
        <button type="button" class="btn btn-primary label_accept">Accept</button>
      </div>
    </div>
  </div>
</div>
<!-- End Label Maker Modal -->

<!-- New Dealer Modal -->
<div class="modal fade" id="NewDealer" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title" id="NewDealerLabel">New Dealer</h4>
      </div>
      <div class="modal-body">

        <div class="row">
            <div class="col-xs-12">
                <label for="NewDealerName">Please enter the dealer name:</label>
                <input type="text" class="form-control" name="NewDealerName" id="NewDealerName">
            </div>
        </div>


      </div>
      <div class="modal-footer group">
        <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
        <button type="button" class="btn btn-primary dealer_accept">Accept</button>
      </div>
    </div>
  </div>
</div>
<!-- End New Dealer Modal -->
</form>

0 个答案:

没有答案